我搞砸了这一点并尝试跟随网上的其他每个例子,但我似乎无法将一个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