110,534
社区成员
发帖
与我相关
我的任务
分享
//把图片转为字节数组
FileStream fs = new FileStream("image path", FileMode.Open);
byte[] imagebytes =new byte[fs.Length];
BinaryReader br = new BinaryReader(fs);
imagebytes = br.ReadBytes(Convert.ToInt32(fs.Length));
br.Close();
fs.Close();
//写数据表
SqlConnection con = new SqlConnection("connection string");
con.Open();
SqlCommand com = new SqlCommand("insert into tab_name(@ImageParam)",con);
com.Parameters.Add("ImageParam", SqlDbType.Image);
com.Parameters["ImageParam"].Value = imagebytes;
com.ExecuteNonQuery();
con.Close();