sSql = "select * from Faculty where RFID='" & txtrfid.Text & "'"
Dim cmd As New OdbcCommand(sSql, con)
Dim dr As OdbcDataReader = cmd.ExecuteReader()
If dr.HasRows Then
dr.Read()
txtfname.Text = dr("fname").ToString()
txtlname.Text = dr("lname").ToString()
txtid.Text = dr("STID").ToString()
txtposition.Text = dr("Pstion").ToString()
txtsubject.Text = dr("Subject").ToString()
Dim bits As Byte() = CType(dr("Pfile"), Byte())'" ERROR HERE!!!""
Dim memo As New MemoryStream(bits)
Dim myimg As New Bitmap(memo)
imgRetrieve.Image = myimg
dr.Close()
答案 0 :(得分:2)
在这种情况下,dr("Pfile")
表达式返回DBNull
值,表示列中没有任何内容。该类型与Byte()
之间没有已知的转换,因此您必须手动执行此操作
Dim data = dr("Pfile")
Dim bits as Byte()
If (TypeOf data is DBNull) Then
bits = new Byte() { }
Else
bits = CType(data, Byte())
End If