登录到程序后,我正在尝试从数据库中检索特定用户的图像。我遇到的问题是“参数无效”。
代码:
Dim ArrImage() As Byte
Dim cn As New SqlConnection("server=.\sqlexpress;Initial Catalog=hazimdb;Integrated Security=True")
Dim Ms As New IO.MemoryStream
Dim da As New SqlDataAdapter("SELECT * FROM userlog WHERE username= '" & Label10.Text.Trim & "'", cn)
Dim dt As New DataTable
da.Fill(dt)
If dt.Rows.Count <> 0 Then
Label10.Text = dt.Rows(0).Item("username")
If Not IsDBNull(dt.Rows(0).Item("pictu")) Then
ArrImage = dt.Rows(0).Item("pictu")
For Each arr As Byte In ArrImage
Ms.WriteByte(arr)
Next
PictureBox8.Image = System.Drawing.Image.FromStream(Ms)
End If
Else
MsgBox("No Match Found")
End If
答案 0 :(得分:1)
在尝试从中获取图像之前,将内存流位置设置为0。
Ms.Flush()
Ms.Position = 0