Please can anyone help me in this code ??
I am trying to retrieve an image from an Access database..
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;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…