I have a PictureBox
control I want to display an image in it. I saved my images in a MS Access database with this data type: OLE Object
.
I find it hard to display it again. Please take a look at my code, and can you guys please devise a solution for it. I got this Exception
:
Unable to cast object of type 'System.Byte[]' to type 'System.Drawing.Image'.
Here's my code:
OleDbCommand cmd = new OleDbCommand("SELECT IMAGE FROM IMAGES WHERE ID = 1", myConn));
cmd.CommandType = CommandType.Text;
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable("dt");
da.Fill(dt);
if (dt != null)
{
pictureBox1.Image = (Image)dt.Rows[0]["IMAGE"];
}