![](/img/trans.png)
[英]Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'.
[英]Unable to cast object of type ' System.dbnull' to type 'system.byte[]'
請幫助。 無法檢索圖像..即時通訊使用Odbc連接..
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()
在這種情況下, 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.