img的导出与写入SQL

读取数据库

1 cmd.CommandText="";
2 adp.SelectCommand=cmd;
3 adp.Fill(dt);
4 byte[] imagebytes=(byte[]) dt.Rows[0][0];
5 MemoryStream ms=new MemoryStream(imagebytes);
6 Bitmap image=new Bipmap(ms);
7 PictureBox.image=image;


写入

1 FileStream fs=new FileStream(filepath, FileMode.Open, FileAccess.Read);
2 //byte[] image=new bt[fs.length];
3 //fs.readbyte(image,0,convert.toinv32(fs.length));
4 BinaryReader br=new BinaryReader(fs);
5 byte[] image=br.readbytes(fs.length);
6 cmd.CommandText=String.Format("insert into 表名(列名)values('{0}')",image);
7 cmd.ExecuteNonQuery();

猜你喜欢

转载自www.cnblogs.com/clarklxr/p/9077100.html
IMG