I am trying to save image in database
codes run successfully
but when i retrive the image it gives error
parameter is not valid on This Line
pbDatbase.Image = Image.FromStream(msImage)
i check in detail the problem is when i save picture i count the bytes
it gives something like 251625 bytes
when i retrieve image it gives only somettimes 8 ,somettimes 16
input image in datbase
Dim strQuery As String
strQuery = “Insert Into tblPictures(Picture) Values(‘@Pic’)”
Using msImage As New MemoryStream
pbFile.Image.Save(msImage, pbFile.Image.RawFormat)
bytImage = msImage.GetBuffer()
MsgBox(bytImage.Count)
Dim cmdImage As New OdbcCommand
dbConnection.Open()
cmdImage.Connection = dbConnection
cmdImage.CommandText = strQuery
cmdImage.Parameters.AddWithValue("@Pic", bytImage)
cmdImage.ExecuteNonQuery()
dbConnection.Close()
cmdImage.Cancel()
End Using
Retrieving Image From Datbase
Dim strQuery As String
strQuery = “Select Picture From tblPictures Where PictureId=(Select Max(PictureId) As ProdId from tblPictures)”
Dim cmdImage As New OdbcCommand
dbConnection.Open()
cmdImage.Connection = dbConnection
cmdImage.CommandText = strQuery
Dim drImage As OdbcDataReader
drImage = cmdImage.ExecuteReader
If drImage.HasRows Then
Dim bytImage() As Byte
bytImage = DirectCast(drImage(“Picture”), Byte())
MsgBox(bytImage.Count)
Dim msImage As New MemoryStream(bytImage)
pbDatbase.Image = Image.FromStream(msImage)
End If
dbConnection.Close()
cmdImage.Cancel()