Hello, Everyone,

I need your help with my code, I am trying to display the image from database to picturebox but I can't figure it out. Below is my code:

Private Sub LoadImage(ByVal ind As Integer)
        Dim cn As New SQLiteConnection("Data Source=C:\db\QC_ASD_2013_08_09.qdb")
        Dim cmd As New SQLiteCommand(String.Concat("SELECT beeld_data FROM image WHERE port_item_id=", ind), cn)
        Dim da As New SQLiteDataAdapter(cmd)
        Dim ds As New DataSet()
        da.Fill(ds, "image")
        Dim c As Integer = ds.Tables("image").Rows.Count
        If c > 0 Then
            Dim bytBLOBData() As Byte = _
                System.Text.Encoding.UTF8.GetBytes(ds.Tables("image").Rows(c - 1)("beeld_data"))
            Dim stmBLOBData As New MemoryStream(bytBLOBData)
            PictureBox1.Image = Image.FromStream(stmBLOBData)
        End If
End Sub

It always says parameter is invalid. Please see below:


Here's the SQlite DB that I am using. ---> http://www.sendspace.com/file/cw8rlm

Recommended Answers

All 7 Replies

Your response will be highly appreciated. Thank you.

I have not used blobs personally, but here is an article.

I hope it helps!

thanks for the link Begginnerdev, I hope other coders can help me.

not yet solve guys :(

It shouldn't really matter, but the function is calling for a stream.

See if this works for you:

     Dim stmBLOBData As New MemoryStream(bytBLOBData)
     Using strm As Stream
         PictureBox1.Image = Image.FromStream(strm)
     End Using

still doesn't work. Thanks for helping Begginnerdev.

One that that does catch my eye is the:


This is grasping for straws: but I am not sure an image should be encoded in UTF8 text format.

You can try something like a direct cast:

  PictureBox1.Image = Image.FromStream(New MemoryStream(DirectCast(ds.Tables("image").Rows(c - 1)("beeld_data"), Byte)))  

To see if that solves your problem as well.

I hope it helps!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.