Results 1 to 4 of 4

Thread: Get image from database

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    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)

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,747

    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

  3. #3
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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

  4. #4
    Hyperactive Member
    Join Date
    Oct 2013
    Posts
    389

    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
  •  



Click Here to Expand Forum to Full Width