
Problem to store image in SQL server 6.0 with VB 4
I too have had the same problem as you, but I have figured out that a byte
array will work quite well.
Example:
Sub StoreImage()
dim bytImage() as byte
dim lTotalSize as long
dim sImageFileName as string
dim rs as rdoResultset
sImageFileName = "C:\Windows\256clr.bmp"
Open sTempFileName For Binary Access Read As #1
lTotalSize = Lof(sTempFileName)
bytImage = InputB(lTotalSize, #1)
Close #1
'This code assumes you have a connection and resulset already
With rs
.AddNew
!Index_ID = 1
!BLOB_Field.AppendChunk = bytImage
.Update
End With
End Sub
To retrieve the image:
Public Sub RetrieveImages()
Dim bytImage() As Byte
Dim sTempFileName As String
bytImage = rs!BLOB_Field.GetChunk(THIS IS THE SIZE OF THE IMAGE)
'Get a unique, temporary filename
sTempFileName = "C:\temp.bmp"
'Copy the binary array to the temp filename
Open sTempFileName For Binary Access Write As #1
Put #1, , bytImage
Close
picImage.Picture = LoadPicture(sTempFileName)
Kill sTempFileName
End Sub
I hope this helps, I think that RDO is the way to go, DAO seems to kludgy
to me.
Regards,
Jason Carpenter