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="insert into 表名(列名)values(@image)";
7 cmd.Parameters.Add("image",SqldbType.Image);
8 cmd.Paramenters["image"].Value=image; 9 cmd.ExecuteNonQuery();