这是我的代码
private void readimagefromdb()
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
string query = "select * from StudentInformation where [StudentID] = " + txtStudentID.Text + "";
command.CommandText = query;
OleDbDataReader read = command.ExecuteReader();
if (picturebox.Image == null)
{
txtStudentFN.Text = (read["Firstname"].ToString());
}
if (picturebox.Image != null)
{
txtStudentFN.Text = (read["Firstname"].ToString());
byte[] image = (byte[])(read["Image"]);
MemoryStream ms = new MemoryStream(image);
StudentPicture.Image = System.Drawing.Image.FromStream(ms);
}
当我的数据没有图片时我收到错误错误:无法将对象类型system.dbnull转换为类型systembyte
我这样做是为了防止错误,每次我添加一个没有图片的新数据..我可以无错误地阅读。抱歉我的英文不好