Insert or Update and long raw datatype

Posted on 1998-11-04
Last Modified: 2013-12-25
I need a source code of a Visual Basic program that's insert or update a row with one long raw datatype (for gif or jpeg images).

-> Visual Basic 4.0 E.E.
-> NT 4.0
-> Driver ODBC (Oracle 73 2.5)

-> Oracle AIX
Question by:arapahoe
1 Comment

Accepted Solution

CarlosJac earned 200 total points
ID: 1497417
If You are using DAO  to access to database, try this code

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

   If IsNull(BinaryField) Then Exit Sub

   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.
   Close nFile

End Sub

Function SaveFileToDB(sSource As String, BynaryField As Field) As Integer
   ' *** Will save a file to a Binary field

   Dim nNumBlocks       As Integer
   Dim nFile            As Integer
   Dim nI               As Integer
   Dim nFileLen         As Long
   Dim nLeftOver        As Long
   Dim sFileData        As String
   Dim Retval           As Variant
   Dim nBlockSize       As Long

   On Error GoTo Error_SaveFileToDB

   nBlockSize = 32000    ' Set size of chunk.

   ' *** Open the sSource file.
   nFile = FreeFile
   Open sSource For Binary Access Read As nFile

   ' *** Get the length of the file.
   nFileLen = LOF(nFile)
   If nFileLen = 0 Then
      SaveFileToDB = 0
      Exit Function
   End If

   ' *** Calculate the number of blocks to read and nLeftOver bytes.
   nNumBlocks = nFileLen \ nBlockSize
   nLeftOver = nFileLen Mod nBlockSize

   ' *** Read the nLeftOver data, writing it to the table.
   sFileData = String$(nLeftOver, 32)
   Get nFile, , sFileData
   BynaryField.AppendChunk (sFileData)

   ' *** Read the remaining blocks of data, writing them to the table.
   sFileData = String$(nBlockSize, Chr$(32))
   For nI = 1 To nNumBlocks
      Get nFile, , sFileData
      BynaryField.AppendChunk (sFileData)
   Close #nFile
   SaveFileToDB = nFileLen

   SaveFileToDB = 0

   Exit Function

   SaveFileToDB = -Err
   Exit Function
End Function


Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

823 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