SQL储存图片的问题

BearRui 2004-04-19 06:58:13
在数据库123中有个表Categories,表中有列Picture,类型为Image,长度为16。

此列中有图片,请问怎么把图片读到pictureBox中和把pictureBox的图片储存到

此列中,先谢谢各位了!!!
...全文
36 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
BearRui 2004-04-20
  • 打赏
  • 举报
回复
谢谢各位指点,我已经搞定了。

再次谢谢!!!
BearRui 2004-04-19
  • 打赏
  • 举报
回复
下面是我的代码,我数据库中图片是第4个字段

Cnn=new SqlConnection("database=123;server=BTK;Trusted_Connection=yes");
Cnn.Open();
Cmd=new SqlCommand("SELECT * FROM Categories",Cnn);
SqlDataReader SqlRead=Cmd.ExecuteReader();
SqlRead.Read();

MemoryStream buf=new MemoryStream((byte[]) SqlRead[3]);
Image image=Image.FromStream(buf,true);

但还是那个错误!!!
麻烦你了!!!
pictureBox1.Image=image;
chenyuming2004 2004-04-19
  • 打赏
  • 举报
回复
reader[0];

里面0是你字段的索引
因为我那程序里面图片是第一个字段,
所以索引是0,
你根据实际情况调整一下。
byte[] ib=new Byte[60000];
数组的大小你可以根据图像文件的实际大小来建立,
你自已把上面的代码稍微修改一下就行了。
bitsbird 2004-04-19
  • 打赏
  • 举报
回复
reader["字段"]
BearRui 2004-04-19
  • 打赏
  • 举报
回复
请问chenyuming2004(一切从2004开始)

MemoryStream buf=new MemoryStream((byte[])reader[0]);

为什么执行到这里的时候就出现错误,说使用无效参数。
stoway 2004-04-19
  • 打赏
  • 举报
回复
向SQL Server数据库添加图片
作者:孟宪会
http://dotnet.aspx.cc/ShowDetail.aspx?id=2A5DD7C6-A45A-48AB-A2E8-342A29F17506
chenyuming2004 2004-04-19
  • 打赏
  • 举报
回复
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;
从数据库读图片到picturebox
chenyuming2004 2004-04-19
  • 打赏
  • 举报
回复
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,再写入数据库
stoway 2004-04-19
  • 打赏
  • 举报
回复
从SQL Server数据库提取图片并显示在DataGrid
作者:孟宪会
http://dotnet.aspx.cc/ShowDetail.aspx?id=ECD9AE16-8FF0-4A1C-9B9F-5E8B641CB1B1

----------------------
http://expert.csdn.net/Expert/topic/2984/2984428.xml?temp=.9140436
stoway 2004-04-19
  • 打赏
  • 举报
回复
向SQL Server数据库添加图片
作者:孟宪会
http://dotnet.aspx.cc/ShowDetail.aspx?id=2A5DD7C6-A45A-48AB-A2E8-342A29F17506
xaodoudou 2004-04-19
  • 打赏
  • 举报
回复
顶,等着学习
BearRui 2004-04-19
  • 打赏
  • 举报
回复
大家帮忙啊

110,538

社区成员

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

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

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