【发布时间】:2017-08-22 13:01:02
【问题描述】:
我正在尝试使用 id 向用户显示图像;它抛出一个异常
从“Byte()”类型到“Byte”类型的转换无效。
当我删除图像代码时;它可以正常显示其他数据。
If rdbtninvestigator.Checked = True Then
Dim mycmd1 As New SqlCommand("Select * From investigator where id=@id ", connection)
mycmd1.Parameters.Add("@id", SqlDbType.VarChar).Value = txtid1.Text
Dim table As New DataTable
Dim adapter As New SqlDataAdapter(mycmd1)
adapter.Fill(table)
If table.Rows.Count > 0 Then
lblid.Text = table.Rows(0)(0).ToString()
lblname.Text = table.Rows(0)(1).ToString()
lblusername.Text = table.Rows(0)(2).ToString()
txtpassword.Text = table.Rows(0)(3).ToString()
Dim img As Byte
img = table.Rows(0)(4)
Dim ms As New MemoryStream(img)
picuser.Image = Image.FromStream(ms)
btnupdate.Enabled = True
btndelete.Enabled = True
Else
MsgBox("Account does not exist")
btnupdate.Enabled = False
btndelete.Enabled = False
End If
【问题讨论】:
-
Dim img As Byte按照你的写法,这个对象代表一个单字节,而不是一个数组。我怀疑你想要Dim img As Byte()之类的东西(对不起,如果这不是正确的 VB 语法。但基本上你需要将它声明为一个数组而不是单个项目)