I just attempted to insert a .jpg image into an access 2010 database but now I want to retrieve it and now I have an error that says "parameter is not valid"

Con.Open()

        Using com As New OleDbCommand("Select Picture from MyImages where ID =1", Con)

            Dim imageobj = com.ExecuteScalar

            If Not imageobj Is Nothing AndAlso Not imageobj Is DBNull.Value Then

                Using ms As New System.IO.MemoryStream

                    Dim bm As Bitmap

                    Dim byteArray = DirectCast(imageobj, Byte())

                    'be aware you see here the way to remove old Ole object information

                    'for not northwind it is normally 0 instead of 78

                    ms.Write(byteArray, 78, byteArray.Length - 78)

                    bm = New Bitmap(ms)'>>>the error shows up here

                    PictureBox1.Image = bm

                End Using

            End If

        End Using

One option you may consider, which will actually save alot of database storage, is to save the path to the image in a text field in your database.

When you are calling the image, just grab the path to the image to be displayed, and you are not saving a large file in your database.

I really need to save the image into the database.Thanks for the suggestion.I made sominor adjustments to the code and it now works

ms.Write(byteArray, 0, byteArray.Length)

Excellent, just mark this thread as solved :)

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.