我在MySQL DB中有一个名为“ Foto”的字段。该字段是一滴。当我使用SQL Server时,以下代码有效:

    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,会产生以下错误:无效的参数。

最佳答案

如果您的ID字段是整数,请查看这是否使您摆脱了该错误。代替这个:

cmd.CommandText = "SELECT Foto FROM MyTable WHERE ID = '" & IDtxt.ToString & "'"


尝试这个:

cmd.CommandText = "SELECT Foto FROM MyTable WHERE ID = " & ctype(int32,IDtxt).ToString

10-08 12:08