当前位置:编程学习 > C#/ASP.NET >>

Winfrom 图片存储

请大哥大姐 帮忙解决 在线等 谢谢了
取图片保存 
byte[] img = (byte[])dt.Rows[0][3];
            MemoryStream ms = new MemoryStream(img);
            pictureBox1.Image = Image.FromStream(ms);
System.IO.Stream)(ms)).ReadTimeout”引发了“System.InvalidOperationException”类型的异常

存储图片 FileStream fs = new FileStream(tbxArea.Text, System.IO.FileMode.Open, System.IO.FileAccess.Read);   //将图片读成数据流
            byte[] buffByte = new byte[fs.Length];
            fs.Seek(0, SeekOrigin.Begin); 
            fs.Read(buffByte, 0, (int)fs.Length);
            fs.Close();
            fs = null;
sql  "UPDATE Weather SET WeatherNo='" + tbxNo.Text.Trim() + "',WeatherName='" + tbxName.Text.Trim() + "',WeatherImg='" + buffByte + "',Remark='" + tbxRemark.Text.Trim() + "',OrderNum='" + cSQL.ToInt(tbxOrderNum.Text.Trim()) + "' WHERE WeatherID=" + CheckNo)
C# --------------------编程问答-------------------- 二进制数据不能直接拼sql更新哦
要用DataSet更新
先根据CheckNo取出记录集ds,然后用ds更新到数据库,这样用流的方式读出图片才没问题
ds.Tables[0]["WeatherNo"]=tbxNo.Text.Trim() ;
ds.Tables[0]["WeatherName"]=tbxName.Text.Trim() ;
ds.Tables[0]["WeatherImg"]=buffByte ;
ds.Tables[0]["Remark"]=tbxRemark.Text.Trim() ;
ds.Tables[0]["OrderNum"]= cSQL.ToInt(tbxOrderNum.Text.Trim()) ;
更新ds到数据库 --------------------编程问答-------------------- http://www.cnblogs.com/tuyile006/archive/2007/01/08/614718.html --------------------编程问答-------------------- http://www.doc88.com/p-292361141823.html
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,