Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 152
  • Last Modified:

Retreiving pictures using SELECT statement

Gretings,
 How can i retreive pictures from my access database
(Table Name:Plane ,Column Name: pl_planepic) using
SELECT Statement(SQL). Pls. help me .

pat_ron.
0
pat_ron
Asked:
pat_ron
1 Solution
 
watyCommented:
You have to use the following function to save the picture from the DB to a file, and show the file in a picture box.

dim record as RecordSet
dim sSQL   as String

sSQL = "Select pl_planepic from Plane"
set record = DB.OpenRecordset(sSQL, dbOpenDynaset)

.
call GetFileFromDB(record("pl_planepic"), "c:\temp\pict.bmp")



Sub GetFileFromDB(BinaryField As Field, szFileName As String)
    ' *** Will retrieve an entire Binary field and write it to disk ***
   
    Dim NumBlocks    As Long
    Dim TotalSize    As Long
    Dim RemBlocks    As Integer
    Dim CurSize      As Integer
    Dim nBlockSize   As Long
    Dim nI           As Integer
    Dim nFile        As Integer
    Dim CurChunk     As String
   
    nBlockSize = 32000    ' Set size of chunk.
   
    ' *** Get field size.
    TotalSize = BinaryField.FieldSize()
    NumBlocks = TotalSize \ nBlockSize   ' Set number of chunks.
   
    ' *** Set number of remaining bytes.
    RemBlocks = TotalSize Mod nBlockSize
   
    ' *** Set starting size of chunk.
    CurSize = nBlockSize
    nFile = FreeFile ' Get free file number.
   
    Open szFileName For Binary As #nFile  ' Open the file.
    For nI = 0 To NumBlocks
       If nI = NumBlocks Then CurSize = RemBlocks
       CurChunk = BinaryField.GetChunk(nI * nBlockSize, CurSize)
       Put #nFile, , CurChunk   ' Write chunk to file.
    Next
    Close nFile

End Sub

0
 
pat_ronAuthor Commented:
Thanks for the answer,
so now how can i Insert picture to the same database using
INSERT INTO statement

pat_ron
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now