“String”类型的值无法转换为“System.Drawing.Image”

时间:2015-11-18 18:12:35

标签: vb.net datagridview picturebox

在我的表单中,我有一个datagridview,4个用于id,firstname,lastname的文本框。中间名和一个图片框,一旦我在datagridview中选择某一行,它将显示和成像。当我点击某一行时,我想在图片框中显示图像。我有一个代码,但我得到了这个错误。

这是我的代码:

    Dim r As DataRow = Access.DBDT.Rows(0)

    txtDelID.Text = r("ID").ToString
    txtDelCourse.Text = r("Course").ToString
    txtDelFname.Text = r("FirstName").ToString
    txtDelLname.Text = r("LastName").ToString
    txtDelMname.Text = r("MiddleName").ToString
    pbDisplay.Image = r("Avatar").ToString

    msiDeleteStud.Enabled = True

End Sub

1 个答案:

答案 0 :(得分:-1)

试试这个

Dim r As DataRow = Access.DBDT.Rows(0)

Dim byteImage() As Byte = r.Item("Avatar")
Dim MStream As New System.IO.MemoryStream(byteImage)
pbDisplay.Image = Image.FromStream(MStream)
txtDelID.Text = r("ID").ToString
txtDelCourse.Text = r("Course").ToString
txtDelFname.Text = r("FirstName").ToString
txtDelLname.Text = r("LastName").ToString
txtDelMname.Text = r("MiddleName").ToString

msiDeleteStud.Enabled = True