当前位置: 代码迷 >> ASP.NET >> 郁闷的有关问题:HttpFileCollection 上传文件和DataGrid 有关问题!
  详细解决方案

郁闷的有关问题:HttpFileCollection 上传文件和DataGrid 有关问题!

热度:3843   发布时间:2013-02-26 00:00:00.0
郁闷的问题:HttpFileCollection 上传文件和DataGrid 问题!!!!在线等!!!!!!!!!
后台代码:
点后进入如下代码:

HttpFileCollection   files   =   HttpContext.Current.Request.Files;  
string strSQL,strSelect,strTable,strOR,strOR1;

System.Text.StringBuilder   strMsg   =   new   System.Text.StringBuilder();  
try  
{  
HttpPostedFile   postedFile   =   files[0];  
  string   fileName   =   System.IO.Path.GetFileName(postedFile.FileName);  
      if   (fileName   ==   " ")
      {
        Msg.Text   =   "Please   choose   a   file. ";
      return;
        }
      if   (fileName.ToLower().IndexOf( ".txt ")   ==   -1)
      {
        Msg.Text   =   "Please   choose   text   file. ";
        return;
        }
        System.IO.Stream   UpLoadStream   =   postedFile.InputStream;
        System.IO.StreamReader   sr   =   new   System.IO.StreamReader(UpLoadStream,   System.Text.Encoding.Default);
    int   Flg=0;
    strOR= " ";
  while   (sr.Peek()   > =   0)
  {
      Flg=1;
    if(Flg==0)
      {
        strOR= "   where     ITEM_ID= ' "+sr.ReadLine()+ " ' ";
      }
        else
      {
      strOR   += "   OR   ITEM_ID= ' "+sr.ReadLine()+ " ' ";
        }
  }
strSelect= "select   a.ITEM_ID,d.CLNT_NAME_J,c.JOB_CD,c.SERVICE_LINE_CD,c.OFF_CD,c.DEP_CD,(c.FILE_TYPE+ '   '+g.FINAL_CLASS_ST_NAME)   as   file_type,c.ACCOUNT_MONTH,b.FILE_NO,b.REPORT_CONTENT,(a.STATUS_CD+ '   '+e.FILE_STATUS_NAME)   as   file_status,(a.ROOM_CD+ '   '+f.ROOM_NAME)   as   file_location   ";

strTable= "   FROM   ((((((REPORT_FILE_TRN_TBL   a   left   outer   join   REPORT_FILE_TBL   b   on   (a.ITEM_ID=b.ITEM_ID))   left   outer   join   REPORT_TBL   c   on   (b.MASTER_CD=c.MASTER_CD))   left   outer   join   CLIENT_TBL   d   on   (c.CLIENT_CD=d.CLNT_NBR))   left   outer   join   FILE_STATUS_TBL   e   on   (a.STATUS_CD=e.FILE_STATUS_CD))   left   outer   join   FILE_ROOM_TBL   f   on   (a.ROOM_CD=f.ROOM_CD))   left   outer   join   FINAL_CLASS_TBL   g   on   (c.FIN_MID_CLASS=g.FINAL_CLASS_CD))   ";

  strSQL=strSelect+strTable+strOR;
SqlConnection   con=cfsnet.createConnection();
con.Open();
SqlDataAdapter   sda=new   SqlDataAdapter(strSQL,con);
DataSet   ds=new   DataSet();
sda.Fill(ds, "ITEM_ID ");
this.DataGrid1.DataSource=ds;
this.DataGrid1.DataKeyField= "ITEM_ID ";
this.DataGrid1.DataBind();
con.Close();
sr.Close();
UpLoadStream.Close();
UpLoadStream   =   null;
sr   =   null;
strMsg.Append( "***********Succeed!*********** "   +   " <br> ");
  相关解决方案