c#存图到数据库

hanzhaorui 2007-08-01 10:41:44
如何把一张图片存到SQLSERVER数据库中,字段类型为IMAGE;
然后再将信息显示到pictureBox中.
...全文
204 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ll124993513 2007-08-01
  • 打赏
  • 举报
回复
用byte[]存进text
gff315 2007-08-01
  • 打赏
  • 举报
回复
先将图片转化为二进制流数组,再存入数据库,然后从数据库中读出二进制来,就可以在picturebox 上显示了
BearRui 2007-08-01
  • 打赏
  • 举报
回复
//把图片读到pictureBox,再写入数据库

SqlConnection conn=new SqlConnection(@"data source=chenyuming2004\VSdotNET;uid=sa;pwd=cym;database=lhf");
conn.Open();
SqlCommand cmd=new SqlCommand("insert into fuser values ('1a','1b',@i)",conn);
byte[] ib=new Byte[60000];
FileStream fs=new FileStream(@"D:\windows temp\temp\1.jpg",FileMode.Open ,FileAccess.Read );
fs.Read(ib,0,60000);
cmd.Parameters.Add("@i",SqlDbType.Image,(int)fs.Length);
cmd.Parameters["@i"].Value=ib;
cmd.ExecuteNonQuery();
conn.Close();

-------------------------------------------------------
//从数据库读图片到picturebox

SqlConnection conn=new SqlConnection(@"data source=chenyuming2004\VSdotNET;uid=sa;pwd=cym;database=lhf");
conn.Open();
SqlCommand cmd=new SqlCommand("select 照片 from fuser where password='1b'",conn);
SqlDataReader reader=cmd.ExecuteReader();
reader.Read();
MemoryStream buf=new MemoryStream((byte[])reader[0]);
Image image=Image.FromStream(buf,true);
pictureBox1.Image=image;
zhaoxiaoyang5156 2007-08-01
  • 打赏
  • 举报
回复

朋友 看看这个问题。http://community.csdn.net/Expert/topic/5686/5686047.xml?temp=.8212702
yaoshuwen 2007-08-01
  • 打赏
  • 举报
回复
还是用byte[]存进text里面好

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧