第一个注意的时数据库类型是 image
第二注意的时 往数据库里插入二进制流的时候用Command的参数形式赋值,然后执行即可。
SqlCommand com = new SqlCommand("Update GG set images=@imgdata where Id='" + xxx + "'",conn);//@imgdata不需要带单引号('') 千万别带
com.Parameters.Add("@imgdata", SqlDbType.Image);
com.Parameters["@imgdata"].Value = imgbt;
com.ExecuteNonQuery();
图片转二进制
string fName=openFileDialog1.FileName;
FileStream fs = new FileStream(fName, FileMode.Open);
byte[] imgbt = new byte[fs.Length];
BinaryReader br = new BinaryReader(fs);
imgbt = br.ReadBytes(Convert.ToInt32(fs.Length));//imgbt 这个就是二进制流
二进制流转图片