I\'m saving a picture in an access database, and everything is OK but when I want to retrieve it I can\'t.
This is my code to save the picture in database. I need code t
But I don't think that you're saving the Image in a Binary format, and even you have not put your last update on this query. So I assume you have saved the Image in a Binary form.
Let's take a look.
I assume that if you've saved the Image in "Long Binary data", then you have to call that Image by using the Image ID
. Or, better, if you're using a Student's Number.
Now what you do here is simply make a TextBox
(i.e. Textbox1). Then follow the code.
Open a Connection first then:
Try
Dim command As New OleDbCommand("SELECT Image FROM Table WHERE Rollno ='" & textbox1.Text & "'", myconnection)
command.Parameters.AddWithValue("@Rollno", Textbox1.Text)
Dim pictureData As Byte() = DirectCast(command.ExecuteScalar(), Byte())
myconnection.Close()
command.Dispose()
Dim stream As New IO.MemoryStream(pictureData)
Me.PictureBox1.Image = Image.FromStream(stream)'See in this picturebox1 you're showing the Image.
'' NOTE: don't dispose the stream!!
Catch ex As Exception
Label3.ForeColor = Color.Red
Label3.Text = "The Given Rollno has not found in the database"
Return
End Try