簡體   English   中英

無法將類型為“ System.String”的對象轉換為類型為“ System.Byte []”的對象。 為什么?

[英]Unable to cast object of type 'System.String' to type 'System.Byte[]'. Why?

將圖像從DataGridViewPictureBox時遇到問題,出現以下錯誤

無法將類型為“ System.String”的對象轉換為類型為“ System.Byte []”的對象

這是我的代碼:

Private Sub BindToText()
    With dgv_EmployeeMainFile
        ... 
        Dim bytes As [Byte]() = .CurrentRow.Cells(31).Value
        Dim ms As New MemoryStream(bytes)
        PictureEmp.Image = Image.FromStream(ms)
    End With
End Sub

假設Cells(31)包含Unicode字符,則可以使用:

System.Text.Encoding.Unicode.GetBytes(str)

供參考: https : //www.dotnetperls.com/convert-string-byte-array-vbnet

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM