|
-
Jun 25th, 2015, 04:46 AM
#1
Get image from database
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.
Lottery is a tax on people who are bad at maths
If only mosquitoes sucked fat instead of blood...
To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)
-
Jun 25th, 2015, 05:29 AM
#2
Re: Get image from database
There are many tutorials for this.
In the database forum FAQ is also a link:
http://www.vbforums.com/showthread.p...-in-a-database
-
Jun 25th, 2015, 10:12 AM
#3
Re: Get image from 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
-
Jun 25th, 2015, 10:18 AM
#4
Re: Get image from database
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|