You need to look at two things: the data that you have in the DB and how you stored it in there, and the data that you have read out.
The code to convert the bytes to an image looks good, so it has to be a problem with the data.
Try it with a small image (make one specially, say 8 by 8 pixels) and see what you get.
Hi, ive tried to do what you said, here it goes:
Dim bytImage() As Byte
Try
Dim ms As New System.IO.MemoryStream
Dim bmpImage As New Bitmap(PictureBox1.Image)
bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
bytImage = ms.ToArray()
ms.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
then to save it to access:
SQL = "INSERT INTO DB VALUES ('" & UserName & "', 'bytImage' )"
my code for retrieving:
the same as above.
im still getting the same error.
You are on the right lines (although you don't need to dim it as a new bitmap - you can use the existing one).
Dim bmpImage As New Bitmap(PictureBox1.Image)
bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
Becomes
PictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
All you need to do is change the way you save it to the DB (You can't just pass the bytes as part of a text string - the DB will try to interpret them as a command and fail)
Using con As New SqlConnection(strConnect)
con.Open()
Using com As New SqlCommand("INSERT INTO myTable (nameOfImageColumnInDB) VALUES (@IMAGE)", con)
com.Parameters.AddWithValue("@IMAGE", bytImage)
com.ExecuteNonQuery()
End Using
End Using
You may need to use OleDbConnection and OleDbCommand instead of SqlConnection and SqlCommand