0
private void Profile_Load(object sender, EventArgs e)
{
    OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=  C:\Users\jay.desai\Documents\Visual Studio 2008\Projects\Employee Profile\Employee.mdb");
    OleDbCommand cmd = new OleDbCommand("select * from Profile where Emp_No=" + txtEmployeeNo.Text + "", con);
    cmd.CommandType = CommandType.Text;
    OleDbDataAdapter da = new OleDbDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds, "Profile");
    txtEmployeeNo.Text = ds.Tables[0].Rows[0][0].ToString();
    txtName.Text = ds.Tables[0].Rows[0][1].ToString();
    txtAddress.Text = ds.Tables[0].Rows[0][2].ToString();
    txtSex.Text = ds.Tables[0].Rows[0][3].ToString();
    txtMobNo.Text = ds.Tables[0].Rows[0][4].ToString();
    dtp.Text = ds.Tables[0].Rows[0][5].ToString();
    textBox1.Text = ds.Tables[0].Rows[0][6].ToString();
    pictureBox1.Image = ds.Tables[0].Rows[0][7];
}

I have created one database in ms access and which have one table called Profile that contain one field Photo has OLE Object Datatype i have mannually inserted one .bmp image in the field now i want to retrieve that image in picturebox but at the run time i got this error "Cannot implicitly convert type 'object' to 'System.Drawing.Image'. An explicit conversion exists (are you missing a cast?)"

Damith
  • 62,401
  • 13
  • 102
  • 153
Jay Desai
  • 821
  • 3
  • 15
  • 42
  • Take a look here http://stackoverflow.com/a/3440372/125740. Same question asked many times. You should have done some research. – Yahya May 20 '13 at 09:47
  • There isn't any need for your + "" at the end of your SQL statement, unless Emp_No is a varchar value in which case you need more single quotes. And of course putting a textboxes value into a SQL statement leaves you wide open to Injection attacks – Mikey Mouse May 20 '13 at 10:17
  • i have done that but still not working – Jay Desai May 20 '13 at 10:28

1 Answers1

0

You need to have Image type object to set Picture Box Image, so you can use memory stream and Image.FromStream method to get the Image

byte[] bimg= (byte[])ds.Tables[0].Rows[0][7];
MemoryStream mstream = new MemoryStream(bimg);
pictureBox1.Image = Image.FromStream(mstream);
Damith
  • 62,401
  • 13
  • 102
  • 153