Hi everyone i'm using vb 2008 for this project and i'm still not so familiar with it so please help me...

I'm trying to display image from MS Access database to another form picturebox but its not working.

this is the error i always encounter -> (System.ArgumentException was unhandled

Message: Parameter is not valid.)

Dim cn As New OleDb.OleDbConnection
        cn.ConnectionString = ""
        cn.Open()

        Dim arrImage() As Byte
        Dim myMS As New IO.MemoryStream
        Dim da As New OleDb.OleDbDataAdapter("SELECT * FROM tblRecords " & _
                                            " WHERE ID=" & Me.txtID.Text, cn)
        Dim dt As New DataTable
        da.Fill(dt)

        If dt.Rows.Count > 0 Then
            Details.lblId.Text = dt.Rows(0).Item("ID") & ""
            Details.txtSpecies.Text = dt.Rows(0).Item("Species") & ""
            Details.txtMutation.Text = dt.Rows(0).Item("Mutation") & ""
            If Not IsDBNull(dt.Rows(0).Item("photo")) Then
                arrImage = dt.Rows(0).Item("photo")
                For Each ar As Byte In arrImage
                    myMS.WriteByte(ar)
                Next
                Details.picPhoto.Image = System.Drawing.Image.FromStream(myMS) <--- here where i'm having error
            End If
        Else
            MsgBox("Record not found!")
        End If
        Details.Show()
        cn.Close()
    End Sub

thank you in advance :)

Edited 4 Years Ago by happygeek: moved from vb forums to vb.net

Not sure if this is the case, but in other languages you need to reset the position of myMS to zero before using it.

How was the photo saved to Access?

Was it written as a BLOB by a program you wrote or was is it added In MS Access 2007 or newer as an attachment?

This article has been dead for over six months. Start a new discussion instead.