c# - how to retrieve photo from access database -
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 * profile 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 1 database in ms access , have 1 table called profile contain 1 field photo has ole object datatype have mannually inserted 1 .bmp image in field want retrieve image in picturebox @ run time got error "cannot implicitly convert type 'object' 'system.drawing.image'. explicit conversion exists (are missing cast?)"
you need have image type object set picture box image, can use memory stream , image.fromstream method image
byte[] bimg= (byte[])ds.tables[0].rows[0][7]; memorystream mstream = new memorystream(bimg); picturebox1.image = image.fromstream(mstream);
Comments
Post a Comment