0
我存储上的表称为测试包含(ID,姓名,图像)图像数据库中的图像,但是当我试图通过使用此代码检索图片:从SQL Server检索数据库错误
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
。
非常感谢StuartLC等。 – user2536447
可以告诉我如何更新存储的数据 – user2536447