参数无效“VB.NET中的错误从sql数据库中反转图像到picturebox

时间:2013-09-12 14:14:35

标签: vb.net

Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim str As String
Dim dr As SqlDataReader

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    str = "select * from llr where llrno='" & TextBox1.Text & "'"
    cmd = New SqlCommand(str, con)
    con.Open()
    dr = cmd.ExecuteReader()
    If dr.HasRows Then
        dr.Read()
        Dim img As Byte() = DirectCast(dr("img"), Byte())
        Dim ms As New MemoryStream(img)
        PictureBox1.Image = Image.FromStream(ms)
    End If
    dr.Close()
    cmd.Dispose()
    con.Close()
End Sub

1 个答案:

答案 0 :(得分:0)

我认为问题可能与上一行有关,请尝试更改为:

Dim img As Byte() = dr("img") 

并查看是否收到同样的错误。