Read from image file into IMAGE column

C

CyberDwarf

Hi,

I have to place images programatically into a SQL Server IMAGE field (ie,to
avoid the drag'n'drop tedium).
OK, I got the recordset to read from the stream..
I also got the recordset to write to the SQL image field.
Only problem left: the SQL field now won't display the image, as it seems to
be the wrong data format!!

Hope someone out there can spot the flaw, as I'm now going cross-eyed!

TIA

Steve
----------------------------------------------------------------
Code:-
=====
(Please note: this has been tested with BMP, JPG & GIF files)
Public Sub SaveImage(strFile As String)
Dim fLen As Integer
Dim bytes() As Byte
Dim f As Field
Dim s As Stream
Set s = New Stream
Dim mstream As ADODB.Stream
'Get file contents into stream
Set mstream = New ADODB.Stream
With mstream
.Type = adTypeBinary
.Open
.LoadFromFile strFile
End With
' Get the stream contents into the field
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
' Initialise and instantiate the rs recordset object then ...
With rs
rs.Open "Select * from photos where ph_compno=42346",
CurrentProject.Connection, adOpenDynamic, adLockPessimistic
rs.Fields("ph_photo").Value = mstream.Read
rs.Update
End With
rs.Close
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top