I have this working code that displays an image in the other form when datagridview is selected
Private Sub dgv1_DoubleClick(sender As Object, e As EventArgs) Handles dgv1.DoubleClick
frmEdit.Show()
Dim ms As New MemoryStream(changephoto(CInt(dgv1.SelectedCells(0).Value)))
frmEdit.PictureBox1.Image = Image.FromStream(ms)
End Sub
Function changephoto(ByVal photo As Integer) As Byte()
cn.Open()
With cmd
.Connection = cn
.CommandText = "SELECT studImage FROM studentInformation WHERE Studentid = " & dgv1.SelectedRows(0).Cells(0).Value
End With
Dim myPhoto() As Byte = CType(cmd.ExecuteScalar(), Byte())
cn.Close()
Return myPhoto
End Function
The problem is when i select a record that has no image,I get this error:
I want the user to select records even if it is no image in the database without having error. Can anyone help me how to fix this. thanks