(转)C#数据库存取图片
2006-12-19 12:57
351 查看
SqlConnection conn=new SqlConnection(@"data source=chenyuming2004VSdotNET;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 emp.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=chenyuming2004VSdotNET;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;
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 emp.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=chenyuming2004VSdotNET;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;
相关文章推荐
- 一起谈.NET技术,c#数据库存取图片的三种方式
- C#实现图片到数据库的存取
- 转 详解C#数据库存取图片三大方式
- C# 数据库中存取图片(照片)及修改时的一些经验之谈
- 小谈c#数据库存取图片的方式
- ASP.NET中存取图片到数据库的示例(C#)
- C# - 数据库存取图片
- C#操作数据库中存取图片文件
- 小谈c#数据库存取图片的方式
- 小谈c#数据库存取图片的方式
- C#存取数据库图片
- C#中将图片转化为byte[]在数据库中存取
- C#操作数据库中存取图片文件的方法
- c#数据库存取图片的三种方式
- 使用C#进行图片的数据库存取
- c#数据库存取图片的方式
- C#实现图片到数据库的存取
- 小谈c#数据库存取图片的方式
- 小谈c#数据库存取图片的三种方式
- C#读取本地磁盘下指定路径下的所有图片,并以二进制存入数据库