请任何人都可以在此代码中帮助我吗?
我正在尝试从 Access 数据库中检索图像..
private void btnRetrieve_Click_1(object sender, EventArgs e)
{
//Save Temporarily that image bytes in one location and give that path to picture box
con.Open();
cmd = new OleDbCommand("select pic from shapes2 where ID= 1", con);
da = new OleDbDataAdapter(cmd);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
if (dt.Rows[0]["pic"] != DBNull.Value)
{
pictureBox4.Image = ByteArrayToImage((Byte[])dt.Rows[0]["pic"]);
}
}
con.Close();
}
Bitmap ByteArrayToImage(byte[] b)
{
MemoryStream ms = new MemoryStream();
byte[] pData = b;
ms.Write(pData, 0, Convert.ToInt32(pData.Length));
Bitmap bm = new Bitmap(ms, false);
ms.Dispose();
return bm;
}