没有给出一个或多个必需参数的值

时间:2013-11-18 20:01:03

标签: vb.net sql-update

我正在尝试使用此更新命令。我有一个访问表,有两个字段,我只是想更新第二个。我已经在我的程序中有这样的代码并且它有效 - 我无法弄清楚为什么这段代码不起作用:

Private Sub Button9_Click(sender As System.Object, e As System.EventArgs) Handles Button9.Click
    Try
        Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=BuddyMatching.accdb;Persist Security Info=False")
        Dim cmd1 As New OleDb.OleDbCommand("Update Priorities set priorityDesc = '" & ComboBox12.Text & "' where priorityNum =1", conn)
        Dim cmd2 As New OleDb.OleDbCommand("Update Priorities set priorityDesc = '" & ComboBox13.Text & "' where priorityNum =2", conn)
        Dim cmd3 As New OleDb.OleDbCommand("Update Priorities set priorityDesc = '" & ComboBox14.Text & "' where priorityNum =3", conn)

        conn.Open()
        cmd1.ExecuteNonQuery()
        cmd2.ExecuteNonQuery()
        cmd3.ExecuteNonQuery()
        conn.Close()

    Catch ex As Exception
        MsgBox(ex.Message)
    End Try
End Sub

每次运行此代码时,都会通过MsgBox返回“没有给出一个或多个必需参数的值”。我的ComboBoxes没有输入空值,所以不是这样。希望另一组眼睛会发现问题。

谢谢!

0 个答案:

没有答案