Hi,
I have had to do exactly this before. The main bits of my code are below. I hope the syntax is right, as I converted it from c# and im not too experienced in
vb...
To insert an Image object into a column, picture, we put the object into an intermediate MemoryStream, then read an array of bytes from it, as that is how it is stored in the database. For an Image myImage:
' save to intermediate MemoryStream
Dim ms As New MemoryStream()
myImage.Save(ms, myImage.RawFormat)
' read byte array from stream
Dim bytBLOB() As New Byte(ms.Length)
ms.Position = 0
ms.Read(bytBLOB, 0, Convert.ToInt32(ms.Length))
' create parameter to insert
Dim parImage As New SqlParameter("@picture", SqlDbType.VarBinary)
parImage.Size = ms.Length
parImage.Value = bytBLOB
' we can now use the parameter in an SqlCommand etc as ususal
To retrieve the image using a SqlDataReader, we reverse the process, but it is much easier:
' read the byte array from the data reader
bytBLOBData = CType(sqldatardr.Item("picture"), Byte());
' create another MemoryStream
Dim msBLOBData As New MemoryStream(bytBLOBData);
' read Image object from MemoryStream
Image myImage = System.Drawing.Image.FromStream(msmBLOBData);
Another method can be found at
http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp
Hope this helps
Philip Cole