我正在尝试从 SQL Server 数据库中读取图像,但出现错误:
参数无效
谁能帮我?如何解决?
byte[] im = connection.ReadImg(id);
if (im != null)
{
MemoryStream st1 = new MemoryStream(im);
pictureBox1.Image = Image.FromStream(st1);
}
else
pictureBox1.Image = Image.FromFile(fn);
public byte[] ReadImg(string id)
{
cmd.Connection = con;
cmd.CommandText = "SELECT photo FROM User WHERE id=" + id;
byte[] image = null;
con.Open();
try
{
image = (byte[])cmd.ExecuteScalar();
}
catch
{
image = null;
}
con.Close();
return image;
}