更新访问数据库VB Net中的图像

时间:2014-11-19 08:21:33

标签: vb.net

尝试更新图片时出错。

这是我过去常用的代码:

Dim data()As Byte         Dim ms As New IO.MemoryStream         Dim i As Short

    Dim conn As New OleDbConnection

    conn = New OleDbConnection(kon)

    conn.Open()

    Dim sql As String = "UPDATE prop SET nmpr ='" & TextBox1.Text & "', peta = @peta where nmr ='" & ComboBox1.Text & "';"

    Try
        Dim cmd As New OleDbCommand(sql, conn)
        'cmd.Connection = conn
        'cmd.CommandType = CommandType.Text

        If PictureBox1 IsNot Nothing Then
            PictureBox1.Image.Save(ms, PictureBox1.Image.RawFormat)
            data = ms.GetBuffer
        Else
            PictureBox1.Image = Nothing
        End If

        cmd.Parameters.Add("@peta", OleDbType.Binary).Value = data
        i = cmd.ExecuteNonQuery

    Catch ex As Exception

        Dim Msg As String = "Unable to update"

        If ex IsNot Nothing Then
            Msg &= ":" & ControlChars.NewLine & ControlChars.NewLine & ex.ToString
        End If

        MessageBox.Show(Msg, My.Application.Info.AssemblyName, MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)

    End Try

    If (i > 0) Then
        MessageBox.Show("Sukses")
    End If

    conn.Close()

错误说:

  

标准表达式中的数据类型不匹配

我不知道哪个不匹配,我只想更新图片(peta)和nmpr字段(texttbox.text)

0 个答案:

没有答案