[英]Gives "System.ArgumentException: 'Parameter is not valid.' " when i retrieving image from database
Help me retrieve an image from database to a PictureBox
.帮助我从数据库检索图像到
PictureBox
。
My code:我的代码:
conn.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM Members WHERE CardID = '" + textBox8.Text + "' OR EMP_ID = '" + textBox8.Text + "'", conn);
SqlDataAdapter daa = new SqlDataAdapter(cmd);
DataSet dss = new DataSet();
daa.Fill(dss);
if (dss.Tables[0].Rows.Count > 0)
{
MemoryStream mss = new MemoryStream((byte[])dss.Tables[0].Rows[0]["Photo"]);
pictureBox1.Image = new Bitmap(mss);
}
conn.Close();
pictureBox1.Image = byteArrayToImage((byte[])dss.Tables[0].Rows[0]["Photo"]);
use below method:使用以下方法:
public Image byteArrayToImage(byte[] byteArrayIn)
{
System.Drawing.ImageConverter converter = new System.Drawing.ImageConverter();
Image img = (Image)converter.ConvertFrom(byteArrayIn);
return img;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.