我对此搞砸了很多,并尝试遵循网络上的所有其他示例,但我似乎无法将 Blob 图像从 MySql DB 拉到图片框中。最终,我希望能够在图片框中显示图片,并让用户能够使用另存为对话框将图片保存到他们的计算机。这是我到目前为止所拥有的,我的错误是当我尝试将图片实际放入图片框中的“picShowPicture.image = Image.FromStream”时,任何帮助将不胜感激。
Imports MySql.Data.MySqlClient
Imports System.IO
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2D
Imports System.Data
Imports System.Windows.Forms
Dim cn As New MySqlConnection
Dim constring As String
constring = "server=localhost;User Id=uid;password=pass;database=default"
Dim cmd As New MySqlCommand
Dim cmdtxt As String
cmdtxt = "SELECT picture FROM test WHERE serial = '" & txtSerial.Text & "'"
With cmd
.Connection = cn
.CommandText = cmdtxt
.CommandType = CommandType.Text
End With
cn.ConnectionString = constring
cn.Open()
Dim da As New MySqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds, "test")
Dim c As Integer = ds.Tables("test").Rows.Count
If c > 0 Then
Dim bytBLOBData() As Byte = _
ds.Tables("test").Rows(c - 1)("picture")
Dim stmBLOBData As New MemoryStream(bytBLOBData)
picShowPicture.Image = Image.FromStream(stmBLOBData)
End If