
How to retrieve a bitmap-image from a SQL Server image field using ADO
I have a bitmap-image stored in an 'image'-type field in a SQL Server
7.0 table. I use this code to retrieve it:
Dim Cn As ADODB.Connection
Dim Rs As ADODB.Recordset
Dim vImage As Variant
Const ChunckSize = 100
Set Cn = CreateObject ("ADODB.Connection")
Set Rs= CreateObject("ADODB.Recordset")
With Cn
(...)
.Execute
End With
Rs.Open "SELECT ImageField FROM Table (...)", Cn, (...)
(...)
While len(vImage) < len(Rs.Field("ImageField").Value)
vImage = vImage & Rs.Fields("ImageField").AppendChunck
(ChunckSize)
(...)
Wend
Picture1.Picture = vImage
(...)
Now Picture1 is a Picture-control and Picture1.Picture expects an object
type. 'vImage' is a variant. This gives a type mismach error.
How can I load the retrieved image (data-type) and put it in the
Picture-control?