Access SQL Update查询没有更新表

时间:2016-01-25 16:18:11

标签: sql vb.net winforms ms-access

我编写了一个代码来进行更新以减少文本框中的某些值 Textbox4.Text with value = "5"减少表格中的PRO_BALANCE字段 Combobox2.Text with value = "30000"符合表格中的PRO_ID字段

   Try
     Dim constr As String = ConfigurationManager.ConnectionStrings("WindowsApplication1.My.MySettings.DatabaseMobileConnectionString").ConnectionString
        'Dim con As New OleDbConnection(constr)
        'Dim cmd As OleDbCommand
        Dim cmdtext As String = "UPDATE  PRODUCT" & _
                              " SET       PRO_BALANCE = PRO_BALANCE -?" & _
                              " WHERE  (PRO_ID = ?)"
      Using con As New OleDbConnection(constr)
            Using cmd As New OleDbCommand(cmdtext, con)
                cmd.CommandType = CommandType.Text
                cmd.Parameters.Add("@pro_Balance", OleDbType.SmallInt).Value = Val(TextBox4.Text)
                cmd.Parameters.Add("@Pro_ID", OleDbType.SmallInt).Value = Val(ComboBox2.Text)
                con.Open()
               cmd.ExecuteNonQuery()
                con.Close()
            End Using
        End Using

    Catch ex As Exception

    End Try

它什么都没发生字段PRO_BALANCE保持相同而不是减少

PRO_ID      PRO_BALANCE
30000       50

它将是

PRO_ID      PRO_BALANCE
30000       45

1 个答案:

答案 0 :(得分:0)

可能有另一个连接阻止写入您的数据库。

确保关闭可能与数据库建立打开连接的任何进程。