public void SaveImage(string MID, OpenFileDialog openF)//将图片以二进制存入数据库中
{
string strimg = openF.FileName.ToString(); //记录图片的所在路径
FileStream fs = new FileStream(strimg, FileMode.Open, FileAccess.Read); //将图片以文件流的形式进行保存
BinaryReader br = new BinaryReader(fs);
byte[] imgBytesIn= br.ReadBytes((int)fs.Length); //将流读入到字节数组中
conn.Open();
StringBuilder strSql = new StringBuilder();
strSql.Append("update tb_employee Set employeePhoto=@Photo where employeeID=" + MID);
SqlCommand cmd = new SqlCommand(strSql.ToString(), conn);
cmd.Parameters.Add("@Photo", SqlDbType.Binary).Value = imgBytesIn;
cmd.ExecuteNonQuery();
conn.Close();
}
“System.Data.SqlClient.SqlException”类型的未经处理的异常在 System.Data.dll 中发生
其他信息: 不能将值 NULL 插入列 'employeePhoto',表 'db_PMS.dbo.tb_employee';列不允许有 Null 值。INSERT 失败。
为什么图片总会成NULL