Hi Peter,
Maybe if you line out this code, it might be of some help.
sorry i havent got the time to line ite out myself....
regards, Leon
Private Const SCONNECT As String = "filedsn=YourDsn.dsn" '
module-level static variable with the filedsn to your
database
Private Sub SavePicture()
Dim iFileHandle As Integer ' Number of
image file to open
Dim rsRecordset as ADODB.Recordset ' recordset to open
Dim sSQLString ' SQL
string
Dim lStartPosition As Long 'Startposition
in the image file for continue reading
Dim iChunkCounter As Integer 'Counter for loop
Dim lChunkSize As Long 'Size of Full
Chunk
Dim lLastChunkSize As Long 'Size of Last
Chunk
Dim iNumberOfWholeChunks As Integer 'Number of full chunks
Dim arrBuffer() As Byte 'byte array
to temporary store the bytes read from the image file.
sSQLString = " SELECT ID_Image, Image FROM Images. '
Set rsRecordSet = New ADODB.Recordset
rsRecordSet.Open sSQL, SCONNECT, adOpenDynamic, adLockOptimistic '
Opening recordset
iFileHandle = FreeFile
'finding free filehandle
Open "c:\MyImage.jpg" For Binary As iFileHandle
'Opening image file
lChunkSize = lGetChunckSize(LOF(iFileHandle)
'Determining full chunksize
iNumberOfWholeChunks = lTotalSize \ lChunkSize
'Determining number of full chunks
lLastChunkSize = lTotalSize Mod lChunkSize
'Determing size of last chunk
ReDim arrBuffer(1 To lChunkSize)
'Redim Array to full chunksize
lStartPosition = 0
'Reset startposition
For iChunkCounter = 1 To iNumberOfWholeChunks
'startloop
Get iFileHandle,lStartPosition, arrBuffer(lChunkSize)
'Filling byte array with chunk
rsRecordset.Fields("Image").AppendChunk (arrBuffer()) 'Saving
chunk
lStartPosition = lStartPosition + lChunkSize
'Next position in file
Next iChunkCounter
ReDim arrBuffer(1 To lLastChunkSize)
'Redim byte array to size of last chunk
Get iFileHandle,lStartPosition, arrBuffer(lLastChunkSize)
'Filling byte array with last chunk
rsRecordset.Fields("Image").AppendChunk (arrBuffer())
'Saving last chunk
Close iFileHandle
'Closing image file
RsRecordset.Update
'Updating recordset
rsRecordset.Close
'Closing recordset
Set rsRecordset = nothing
End Sub
Quote:> > Private Function lGetChunckSize(ByVal lWholeSize As Long) As Long
> > Select Case lWholeSize
> > Case 0 To 100
> > lGetChunckSize = 10
> > Case 100 To 1024
> > lGetChunckSize = 100
> > Case 1024 To 8192
> > lGetChunckSize = 1024
> > Case 8192 To 32768
> > lGetChunckSize = 4096
> > Case Is > 32768
> > lGetChunckSize = 8192
> > Case Else
> > MsgBox lWholeSize
> > End Select
> > End Function
Private Sub GetPicture(ByVal PriKey As Integer)
Dim rsRecordset As ADODB.Recordset
Quote:> > Dim arrBuffer() As Byte
> > Dim sSQLString as string
Dim sTempFile as string
Dim iFileHandle as integer
sSQLString = " SELECT ID_Image, Image FROM Images WHERE ID_Image = " &
PriKey '
Set rsRecordSet = New ADODB.Recordset
rsRecordSet.Open sSQL, SCONNECT, adOpenDynamic, adLockOptimistic '
Opening recordset
arrBuffer() =
rsRecordset.Fields("Image").GetChunk(rsRecordset.Fields("Image").ActualSize)
'getting all of the image into byte array
sTempFile = App.Path & "\output.bin"
Quote:> > iFileHandle = FreeFile
> > Open sTempFile For Binary As iFileHandle
'Opening temporary file
Quote:> > Put iFileHandle, , arrBuffer()
'Writing byte array to temp file
Quote:> > Close iFileHandle
'Closing tempfile
Set imgImage.Picture = LoadPicture(sTempFile, , vbLPColor) 'Load
ing image into image control
Quote:> > Kill sTempFile
'Deleting temp file
rsRecordset.close
Set rsRecordset = nothing
End Sub
> Hello,
> I'm looking for two procedures, one to move a graphical file (jpeg, gif,
> ...) into an image field in SQL Server7.0, and one to retrieve the image
> from the database and put it back into a graphical file.
> Thanks in advance,
> Peter Roothans,
> Belgium