免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
用ado.net對word,excel進行存取

blob表

3 id int 4 0
0 name char 50 1
0 blob image 16 1
0 type char 60 1

saveFile.aspx.cs

  private void Button1_Click(object sender, System.EventArgs e)
  {
   Stream imgdatastream = File1.PostedFile.InputStream;
   int imgdatalen = File1.PostedFile.ContentLength;
   string imgtype = File1.PostedFile.ContentType;
   string name = this.getFileNameByURL(this.File1.PostedFile.FileName);
   byte[] imgdata = new byte[imgdatalen];
   int n = imgdatastream.Read(imgdata,0,imgdatalen);
   string connstr =  "workstation id=OVERMIND;packet size=4096;user id=sa;password=sa;data source=OVERMIND;persist security info=False;initial catalog=wztj";
   SqlConnection connection = new SqlConnection(connstr);
   SqlCommand command = new SqlCommand("INSERT INTO blob(name,type,blob)  VALUES ( @imgtitle, @type,@blob )", connection );
   SqlParameter paramTitle = new SqlParameter("@imgtitle", SqlDbType.VarChar,50 );
   paramTitle.Value = name;
   command.Parameters.Add(paramTitle);
   SqlParameter paramData = new SqlParameter( "@blob", SqlDbType.Image );
   paramData.Value = imgdata;
   command.Parameters.Add( paramData );
   SqlParameter paramType = new SqlParameter( "@type", SqlDbType.VarChar,50 );
   paramType.Value = imgtype;
   command.Parameters.Add( paramType );
   wztj.debug.TestSQL.TraceErrorSql("INSERT INTO blob(name,type,blob)  VALUES ( @imgtitle, @type,@blob )",command.Parameters);
   connection.Open();
   int numRowsAffected = command.ExecuteNonQuery();
   connection.Close();
  }

listFile.aspx//這個東西主要用來列表,把已經有的東西列出來

<asp:HyperLinkColumn DataNavigateUrlField="id" HeaderText="產品名稱" DataNavigateUrlFormatString="./getFile.aspx?ID={0}" DataTextField="name" DataTextFormatString="{0}" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="160px">

listFile.aspx.cs

   string connstr="workstation id=OVERMIND;packet size=4096;user id=sa;password=sa;data source=OVERMIND;persist security info=False;initial catalog=wztj";
   SqlConnection connection = new SqlConnection(connstr);
   SqlCommand command = new SqlCommand("select * from blob", connection );
   connection.Open();
   SqlDataAdapter adaptor = new SqlDataAdapter(command);
   DataSet ds = new DataSet();
   adaptor.Fill(ds,"blob");
   connection.Close();
   this.DataGrid1.DataSource=ds.Tables["blob"].DefaultView;
   this.DataGrid1.DataBind();

getFile.aspx.cs//這個文件比較重要負責把村道數(shù)據(jù)庫里面的文件,按照格式,按照名稱,給傳輸出來

  private void Page_Load(object sender, System.EventArgs e)
  {
   string imgid =this.Request.QueryString.Get("ID");
   //Request.QueryString["imgid"];
   string connstr="workstation id=OVERMIND;packet size=4096;user id=sa;password=sa;data source=OVERMIND;persist security info=False;initial catalog=wztj";
   string sql="SELECT name,blob, type FROM blob WHERE id = " + imgid;
   SqlConnection connection = new SqlConnection(connstr);
   SqlCommand command = new SqlCommand(sql, connection);
   connection.Open();
   SqlDataReader dr = command.ExecuteReader();
   if(dr.Read())
   {
    Response.Clear();
    Response.Buffer= true;
    Response.Charset="GB2312";   
    Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//設置輸出流為簡體中文
    //Response.ContentType = "application/ms-word";//設置輸出文件類型為word文件。
    Response.ContentType = dr["type"].ToString();
    Response.BinaryWrite( (byte[]) dr["blob"] );
    string FileName = dr["name"].ToString().Trim();
    FileName=System.Web.HttpUtility.UrlEncode(FileName,System.Text.Encoding.UTF8 );
    Response.AppendHeader("Content-Disposition", "attachment;filename="+FileName);
   }
   connection.Close();
  }


這里要說的有兩點,第一,就是把文件的名稱getFile.aspx變成我們想要的名稱。

 Response.AppendHeader("Content-Disposition", "attachment;filename="+FileName);

第二,就是把指定的名稱變成我們想要的值,是標準的中文,而不是中文的亂碼。

 FileName=System.Web.HttpUtility.UrlEncode(FileName,System.Text.Encoding.UTF8 );

本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
《C#語言程序設計項目教程》第9章 ADO.NET數(shù)據(jù)庫訪問技術寫字字帖
ADO.NET的記憶碎片(一)
Web.config之連接字介紹
ASP.net連接SQL數(shù)據(jù)庫的源代碼
ASP.NET操作數(shù)據(jù)庫的 ADO.NET
.NET基礎拾遺(6)ADO.NET與數(shù)據(jù)庫開發(fā)基礎
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服