VB.NET:从MySQL DB中恢复图像(blob) [英] VB.NET: Retrive an image (blob) from MySQL DB
本文介绍了VB.NET:从MySQL DB中恢复图像(blob)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在MySQL DB中有一个名为Foto的字段。这个字段是一个blob。当我使用SQL Server时,以下代码有效:
I've a field called "Foto" in MySQL DB. This field is a blob. When I used SQL Server, the following code worked:
Dim conn As New MySqlConnection
conn.ConnectionString = ConnectionString
Dim cmd As New MySqlCommand
cmd.Connection = conn
conn.Open()
cmd.CommandText = "SELECT Foto FROM MyTable WHERE ID = '" & IDtxt.ToString & "'"
Dim reader As MySqlDataReader
reader = cmd.ExecuteReader
While reader.Read
If (IsDBNull(reader("Foto"))) Then
frmCartaIdentitaView.pctImage.Image = Nothing
Else
Dim byteImage() As Byte = reader("Foto")
Dim frmImageView stmFoto As New System.IO.MemoryStream(byteImage)
frmImageView.pctImage.Image = Image.FromStream(stmFoto)
frmImageView.pctImage.SizeMode = PictureBoxSizeMode.Zoom
frmImageView.Show()
End If
End While
但是现在我正在使用mysql,产生以下错误:无效参数。
But now that I'm using mysql, is produced the following error: invalid parameter.
推荐答案
如果您的ID字段是整数,请查看是否会让您超过该错误。而不是:
If your ID field is an integer, see if this gets you past that error. Instead of this:
cmd.CommandText = "SELECT Foto FROM MyTable WHERE ID = '" & IDtxt.ToString & "'"
试试这个:
cmd.CommandText = "SELECT Foto FROM MyTable WHERE ID = " & ctype(int32,IDtxt).ToString
这篇关于VB.NET:从MySQL DB中恢复图像(blob)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文