gpt4 book ai didi

mysql - 使用 vb.net 从 Mysql 检索图像

转载 作者:行者123 更新时间:2023-11-30 00:11:28 25 4
gpt4 key购买 nike

我已经将图像存储为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但给出错误说“参数无效,出了什么问题?”

最佳答案

您正在创建一个MemoryStream,但没有向其中写入任何数据。图像数据不会神奇地从流中出来;而是会从流中出来。你必须先把它放在那里。您读过 MemoryStream 类吗?如果您有,那么您就知道它有一个构造函数,允许您传入 Byte 数组。您有一个包含图像数据的 Byte 数组,因此这是天作之合。

此外,请确保在使用 MemoryStream 后对其进行处置。

关于mysql - 使用 vb.net 从 Mysql 检索图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24005859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com