我将图像存储到名为 test contains (id,name,image) 的表上的数据库中,但是当我尝试使用以下代码检索图像时:
SqlConnection CN = new SqlConnection(constring);
SqlCommand cmd = new SqlCommand("select * from test where id ='"+txtid.Text+"'", CN);
SqlDataReader myreader;
try
{
CN.Open();
myreader = cmd.ExecuteReader();
if (myreader.HasRows)
{
txtid.Text = myreader[0].ToString();
txtname.Text = myreader[1].ToString();
byte[] img = (byte[])(myreader[2]);
if (img == null)
pictureBox1.Image = null;
else
{
MemoryStream ms = new MemoryStream(img);
pictureBox1.Image = Image.FromStream(ms);
}
}
else
{
MessageBox.Show("do not found");
}
CN.Close();
}
catch (Exception ex)
{ MessageBox.Show(ex.Message); }
我有这个错误:invalid attempt to read when no data is present
。