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

Edited by renzlo

3 Years
Discussion Span
Last Post by Begginnerdev

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

Edited by renzlo


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

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!

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.