问题一直没有解决啊,请高手帮忙

q23tr34t 2004-10-21 12:41:35
我想每按一次按钮就向SQL sever 数据库中的 list 表中插入一张图片,请问代码怎样编?


private void Button1_Click(object sender, System.EventArgs e)
{

}
...全文
82 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
BearRui 2004-10-21
  • 打赏
  • 举报
回复
//把图片读到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;
yaopeng117 2004-10-21
  • 打赏
  • 举报
回复
学习拉

110,538

社区成员

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

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

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