Hey folks,
I am searching now several days for the right answer so therefore I ask
here. Hope someone can help.
In a table "tbl_pictures" there are stored image-data in a field defined as
data-type image (size 16). I know the data-type is depreciated but I have
to handle with it now.
I want to show this image data in a vb.net-windows-form-picturebox when I
click a button. This I was trying to do but it doesn't work:
Private Sub Button1_Click(sender As Object, e As System.EventArgs)
Handles Button1.Click
getImageData("11000000")
End Sub
Private Sub getImageData(ByVal IN_ID As String)
Dim conns as String = "Server=XXX007;DataBase=MyDB;Integrated
Security=SSPI"
dim m_CON1 as SqlConnection = New SqlConnection(conns)
Dim ds As New DataSet
Dim sqlString As String = "SELECT PIC FROM tbl_pictures
WHERE(PIC_ID = " & IN_ID & ")"
Dim cmd As New SqlCommand
Dim da As SqlDataAdapter
Try
cmd.Connection = m_CON1
cmd.CommandText = sqlString
da = New SqlDataAdapter(cmd)
da.Fill(ds, "MyPictures")
Dim i As Integer = ds.Tables("MyPictures").Rows.Count
If i > 0 Then
Dim bytBLOBData() As Byte =
CType(ds.Tables("MyPictures").Rows(i - 1).Item(0), Byte())
Dim stmBLOBData As New MemoryStream(bytBLOBData)
PictureBox1.Image = Image.FromStream(stmBLOBData)
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
m_CON1.Close()
End Try
End Sub
the error comes with
PictureBox1.Image = Image.FromStream(stmBLOBData)
Error message is "Parameter is not valid". In debug mode exception is
printing this: "an exception (first chance) of type
"System.ArgumentException" occurs in System.Drawing.dll.
When I open the preview of the dataset result it says the field is
System.Byte[]
What is my mistake?
Joerg
--
You received this message because you are subscribed to the Google
Groups "DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML
Web Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/dotnetdevelopment?hl=en?hl=en
or visit the group website at http://megasolutions.net