Solved

Retreiving pictures using SELECT statement

Posted on 1998-09-07
2
145 Views
Last Modified: 2010-04-30
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
Comment
Question by:pat_ron
2 Comments
 
LVL 14

Accepted Solution

by:
waty earned 30 total points
ID: 1433492
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
 

Author Comment

by:pat_ron
ID: 1433493
Thanks for the answer,
so now how can i Insert picture to the same database using
INSERT INTO statement

pat_ron
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question