我在mysql中将图像存储为blob,现在我想在Vb的图片框中显示此图像, 我使用了以下代码..
Dim con As New MySqlConnection
Dim str As String = "host=localhost;userid=root;password=;database=new;"
Dim qry As String = "select pic from img where id='1'"
Dim cmd As MySqlCommand
Dim reader As MySqlDataReader
Dim dt() As Byte
con.ConnectionString = str
Try
con.Open()
MsgBox(con.State)
cmd = New MySqlCommand(qry, con)
reader = cmd.ExecuteReader()
reader.Read()
dt = reader.Item("pic")
Dim mstream As New System.IO.MemoryStream
PictureBox1.Image = Image.FromStream(mstream)
reader.Close()
Catch ex As Exception
MsgBox(ErrorToString)
End Try
显示连接状态= 1 但是给出错误说“参数无效,错误?”
答案 0 :(得分:0)
您正在创建MemoryStream
但不会向其写入任何数据。图像数据不会神奇地从流中出来;你必须先把它放在那里。你有没有阅读MemoryStream
课程?如果你有,那么你知道它有一个允许你传入Byte
数组的构造函数。你有一个包含图像数据的Byte
数组,这样就可以在天堂进行匹配。
另外,请确保在使用后放置MemoryStream
。