In a MS Access database I have a table field for images which I input as attachments. Now, how do I retrieve them with VB code and display them on a picturebox? I connect using ADO.
Printable View
In a MS Access database I have a table field for images which I input as attachments. Now, how do I retrieve them with VB code and display them on a picturebox? I connect using ADO.
There are many tutorials for this.
In the database forum FAQ is also a link:
http://www.vbforums.com/showthread.p...-in-a-database
Most of the tutorials miss one point though.
You are generally going to be far, far better off storing images in their raw "on-disk format" rather than as a persisted StdPicture. However while this works for retrieval automagically with databound controls, more work is required if you fail to use data binding.
While you could do something like retrieve the raw bytes, write a temporary disk file, then LoadPicture back there is an easier way. Here a "Pictures" table with a "Pic" field is opened, and its format is specified to be a picture so that Field.Value returns a StdPicture object instead of the raw Byte array:
Code:'Ref to: Microsoft Data Formatting Object Library 6.0 (SP6)
Dim FmtPic As StdFormat.StdDataFormat
Set FmtPic = New StdFormat.StdDataFormat
FmtPic.Type = fmtPicture
Set RS = New ADODB.Recordset
With RS
.Open "Pictures", Conn, adOpenKeyset, adLockReadOnly, adCmdTableDirect
Set .Fields![Pic].DataFormat = FmtPic
End With
krtxmrtz, do yourself and the people who will have to maintain your code later on, a favor, put the path of the image file on the database, and store the image file on a hard-disk \ network shared drive.
it will save you so much headache, soo much.