0

I'm trying to retrieve an image stored in an Access Database to a Picturebox. I'm not very fluent with this language, but my current code is as follows:

Private Sub lstUsers_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstUsers.SelectedIndexChanged

    Dim dt As New DataTable

    dt = runSQL("Select * from tblUser where UserName = '" & lstUsers.SelectedItem.ToString & "'")

    txtForename.Text = dt.Rows(0)(2)
    txtSurname.Text = dt.Rows(0)(3)
    txtCode.Text = dt.Rows(0)(6)
    txtFinish.Text = dt.Rows(0)(7)
    Dim data As Byte() = DirectCast(dt.Rows(0)(8), Byte())
    Using ms As New MemoryStream(data)
        Me.PictureBox1.Image = Image.FromStream(ms)
    End Using

End Sub

When I try to run it and I select a username I get the following error message pointing to Image.FromStream(ms):

Parameter is not valid.

Any help would be appreciated.

Zabloski
  • 21
  • 2
  • Have you looked at this [SO post](http://stackoverflow.com/questions/21443467/how-to-load-picture-into-ms-access-image-control-from-ado-recordset-field)? – vmachan Jan 08 '17 at 00:57
  • Just checked it, but I honestly don't understand much. – Zabloski Jan 08 '17 at 01:04
  • [This answer](http://stackoverflow.com/a/19999243/2144390) shows how to convert an array of bytes into a PictureBox `.Image` via a `System.IO.MemoryStream`. – Gord Thompson Jan 08 '17 at 14:06
  • @GordThompson I have made the following improvements but I keep getting the error Parameter is not valid. – Zabloski Jan 11 '17 at 21:40

0 Answers0