L
Lindsey Howell
Hello,
I've encountered a problem when trying to display BLOB images from a SQL
database using VB.NET. This is the code which generates the error:
Dim mySqlConnection As SqlConnection = New
SqlConnection(connectionString)
Dim mySqlCommand As SqlCommand = New SqlCommand(queryString,
mySqlConnection)
Dim ms as MemoryStream = New MemoryStream
mySqlConnection.Open()
Dim img() As Byte = CType(mySqlCommand.ExecuteScalar,
Byte())
ms.Write(img, 0, img.Length)
Dim bmp As Bitmap = New Bitmap(ms)
Response.ContentType = "image/gif"
bmp.Save(Response.OutputStream, ImageFormat.Gif)
mySqlConnection.Close()
mySqlConnection = Nothing
ms.Close()
This approach is suggested on several websites. However, when i run the code
it errors on the line where the bitmap (bmp) is declared, with the error
message:
System.ArgumentException: Invalid parameter used. at
System.Drawing.Bitmap..ctor(Stream stream) at ...
Does anyone have an ideas what could be causing this?
Thanks,
Lindsey
I've encountered a problem when trying to display BLOB images from a SQL
database using VB.NET. This is the code which generates the error:
Dim mySqlConnection As SqlConnection = New
SqlConnection(connectionString)
Dim mySqlCommand As SqlCommand = New SqlCommand(queryString,
mySqlConnection)
Dim ms as MemoryStream = New MemoryStream
mySqlConnection.Open()
Dim img() As Byte = CType(mySqlCommand.ExecuteScalar,
Byte())
ms.Write(img, 0, img.Length)
Dim bmp As Bitmap = New Bitmap(ms)
Response.ContentType = "image/gif"
bmp.Save(Response.OutputStream, ImageFormat.Gif)
mySqlConnection.Close()
mySqlConnection = Nothing
ms.Close()
This approach is suggested on several websites. However, when i run the code
it errors on the line where the bitmap (bmp) is declared, with the error
message:
System.ArgumentException: Invalid parameter used. at
System.Drawing.Bitmap..ctor(Stream stream) at ...
Does anyone have an ideas what could be causing this?
Thanks,
Lindsey