OLE DB object error when convert binary to image, error paremeter is not valid RRS feed

  • Question

  • I have a column that stored picture in an MS Access database. In that column I right-click it and insert object which is picture from file
    and it said "package" in the column and not "long binary file"

    The idea is to upload picture to 'pic' column in access database from file, and using 'querypic' table adapter query with parameter is 'comboname.text' is selected to return picture and store it as binary in byte of array

    but when i convert it to image i got an error 

    > System.ArgumentException: 'Parameter is not valid.

    I checked my b() which is array of byte and it got result {length=40276}

    this probably because of the OLEDB object in pic that i upload directly to access and not RAW binary file

    can someone help me and can solve this? 

        Private Sub cmdSelect_Click(sender As Object, e As EventArgs) Handles cmdSelect.Click
                Dim facultytabeladapt As New CSE_DEPTDataSetTableAdapters.FacultyTableAdapter
                Dim b() As Byte
                Dim s As String
                b = facultytabeladapt.querypic(ComboName.Text)

                PhotoBox.Image = b21(b)

            End Sub
            Private Function b21(ByVal b() As Byte) As Image

                Dim imgc As New ImageConverter

                Dim imgpic As Image = CType(imgc.ConvertFrom(b), Image) 'it has error "System.ArgumentException: 'Parameter is not valid."
                Return imgpic
            End Function

    Friday, September 7, 2018 2:02 PM

All replies

  • Hi dedev,

    Please try the following code, which use MemoryStream

    Private Function b21(ByVal b() As Byte) As Image
        Dim imgpic as Image
        Dim ms as System.IO.MemoryStream = New 
        imgpic = System.Drawing.Image.FromStream(ms)
        Return imgpic
    End Function

    Best regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, September 10, 2018 1:30 AM