retrieving images from SQL

kyleolson

New member
Joined
Sep 9, 2008
Messages
2
What am I doing wrong????? :confused:



Dim oSQLConn As SqlConnection = New SqlConnection()
Dim dr As SqlDataReader
oSQLConn.ConnectionString = ConnString

Dim strSQL As String
Get Items..
strSQL = "SELECT object FROM images where type = logo2"
oSQLConn.Open()


Dim cmd As New SqlCommand(strSQL, oSQLConn)
dr = cmd.ExecuteReader
dr.Read()
picLogo.Image = Nothing
MsgBox(dr.Item("type"))
Dim bytImageData() As Byte = dr.Item("object")
Dim stmImageData As New MemoryStream(bytImageData)
picLogo.Image = Image.FromStream(stmImageData)
 
Are you getting any errors when you are using the above code or is it just not displaying the image?

If you step through the code does bytImageData get assigned anything on the line
Code:
Dim bytImageData() As Byte = dr.Item("object")

Have you tried the GetSqlBytes method of the SqlDataReader? This exposes a Stream property you can use directly without needing to copy data into a bytre array etc.
 
Back
Top