hi
i have problem in retrieving picture in picturebox
i have a dataset named "DS" and i have built memberPhotoTableAdapter in it.
i call the MemberPhotoTableAdapter in form load by this code:
Me.MembersPhotoTableAdapter.FillBy(Me.DS.MembersPhoto, NationalCode.ToString())
this is the codes to insert picture in database :
Private Sub btnSavePic_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSvePic.Click
Try
Dim ms As New MemoryStream()
Photo.Image.Save(ms, Photo.Image.RawFormat)
Dim arrPic As Byte() = ms.GetBuffer()
ms.Close()
MembersPhotoTableAdapter.InsertQuery(arrPic, NationalCode.ToString())
MsgBox("pic saved")
Catch ex As Exception
MsgBox("Error")
End Try
End Sub
this code works well,but for retrieving the picture i have problem.
this is the code for retrieving picture in form_Load:
Dim arrPic As Byte()
arrPic = DirectCast(DS.Tables("MembersPhoto").Rows(0)("pic"),Byte())
Dim ms As MemoryStream = New MemoryStream(arrPic)
Photo.Image = New Bitmap(ms)
i know that the bold line is wrong and in running time shows error, for the persons that i have inserted picture for them before, shows this error:
error: the parameter is not valid
and for the persons without picture showes this error:
error : there is no row in position 0.
but what shuold i write insted of that
thanks alot