I'm trying to use AxHost.GetPictureFromIPicture() to get a GIF image (saved as an attachment type) from MS Access 2013 database file (*.accdb) - convert it to Image so I can display it in a PictureBox. But the method is not there! :( Am I missing something? Do I need to set or install smtg?
Without conversion I get this error: "Unable to cast COM object of type 'System.__ComObject' to class type 'System.Drawing.Image'"
Do I actually do the whole thing the right way? Or is there a better solution? Please, help me.
DBEngine dbe = new DBEngine();
Database db = dbe.OpenDatabase("Database1.accdb", false, false, "");
Recordset rs = db.OpenRecordset("select solution from tab2 where id = 1", RecordsetTypeEnum.dbOpenDynaset, 0, LockTypeEnum.dbOptimistic);
rs.MoveFirst();
object o = rs.Fields[0].Value;
Image img = (Image)o; -> error
Image img = AxHost.GetPictureFromIPicture(o); - the method is missing
pictureBox1.Image = img;
rs.Close();
The documentation for the AxHost Class says
I must admit that I have not tried that approach. To the best of my knowledge the only way to reliably extract a file from an Attachment field in an Access database is to use the
.SaveToFile()
method of an ACE DAOField2
object. In your case, the code would look something like this: