Working with pictures in MS Access and SQL Server

后端 未结 1 1575
离开以前
离开以前 2021-01-19 07:00

How exactly does one go about:

  1. getting images/pictures into a SQL database
  2. viewing pictures from a SQL database using a MS Access form?

相关标签:
1条回答
  • 2021-01-19 07:32

    Getting pictures in and out of an SQL Server database:

    You need the GetChunk and AppendChunk functions for that.
    Here's a tutorial: How To Read and Write BLOBs Using GetChunk and AppendChunk.
    This tutorial is a bit dated, but as far as I know this is still the best way to load/save pictures in a database from VBA.
    Note that in SQL Server, you should use a varbinary(max) field (instead of the image suggested in the tutorial) to store the pictures.

    Displaying the pictures in an MS Access form:

    You can't display a picture directly from the database. You have to load it from the database (see above), store it in a temp folder and display it from there.

    To get Windows' temp folder, use Environ("temp") or the GetTempPath API function.

    To display the picture you can either set it as the background of the form:

    Me.Picture = "c:\...\temp\picture.jpg"
    

    ...or use a image control:

    Me.NameOfImageControl.Picture = "c:\...\temp\picture.jpg"
    
    0 讨论(0)
提交回复
热议问题