使用删除按钮后,VB.NET保存按钮停止工作

时间:2015-08-20 18:25:43

标签: sql database vb.net ms-access

好吧所以我在我的保存中运行一些sql事务从库存中扣除一些金额,我在删除按钮中有一些sql事务添加回库存但是当我使用删除按钮时我的保存按钮不再工作< / p>

保存按钮

    If cmbProduct.Text = "100LB Saltbread" And chkBajanFlour.Checked = True And chkBrownSugar.Checked = True Then
                ' Open the db connection
                Dim Con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Stock Manager.accdb")
                Con.Open()

                ' Start Transaction
                Dim Trans = Con.BeginTransaction

                'define a comand for the sql statement
                Dim CMD As New OleDb.OleDbCommand("SELECT Amount FROM [Recipes] WHERE RecipeID=1", Con, Trans)
                Dim i = CMD.ExecuteScalar()
                Dim CMD2 As New OleDb.OleDbCommand("Update [Stock] set Amount=(Amount-@TT) where ItemID=10", Con, Trans)
                CMD2.Parameters.AddWithValue("@TT", i * txtAmount.Text)


                Dim CMD3 As New OleDb.OleDbCommand("SELECT Amount FROM [Recipes] WHERE RecipeID=2", Con, Trans)
                Dim q = CMD3.ExecuteScalar()
                Dim CMD4 As New OleDb.OleDbCommand("Update [Stock] set Amount=(Amount-@TT) where ItemID=22", Con, Trans)
                CMD4.Parameters.AddWithValue("@TT", q * txtAmount.Text)

                Dim CMD5 As New OleDb.OleDbCommand("Select Amount from [Recipes] where RecipeID=3", Con, Trans)
                Dim w = CMD5.ExecuteScalar()
                Dim CMD6 As New OleDb.OleDbCommand("Update [Stock] set Amount=(Amount-@TT) where ItemID=21", Con, Trans)
                CMD6.Parameters.AddWithValue("@TT", w * txtAmount.Text)

                Dim CMD7 As New OleDb.OleDbCommand("Select Amount from [Recipes] where RecipeID=4", Con, Trans)
                Dim r = CMD7.ExecuteScalar()
                Dim CMD8 As New OleDb.OleDbCommand("Update [Stock] set Amount=(Amount-@TT) where ItemID=85", Con, Trans)
                CMD8.Parameters.AddWithValue("@TT", r * txtAmount.Text)

                Dim CMD9 As New OleDb.OleDbCommand("Select Amount from [Recipes] where RecipeID=5", Con, Trans)
                Dim d = CMD9.ExecuteScalar()
                Dim CMD10 As New OleDb.OleDbCommand("Update [Stock] set Amount=(Amount-@TT) where ItemID=8", Con, Trans)
                CMD10.Parameters.AddWithValue("@TT", d * txtAmount.Text)

                Dim CMD11 As New OleDb.OleDbCommand("Select Amount from [Recipes] where RecipeID=6", Con, Trans)
                Dim g = CMD11.ExecuteScalar()
                Dim CMD12 As New OleDb.OleDbCommand("Update [Stock] set Amount=(Amount-@TT) where ItemID=107", Con, Trans)
                CMD12.Parameters.AddWithValue("@TT", g * txtAmount.Text)

                Dim CMD13 As New OleDb.OleDbCommand("Select Amount from [Recipes] where RecipeID=7", Con, Trans)
                Dim v = CMD13.ExecuteScalar()
                Dim CMD14 As New OleDb.OleDbCommand("Update [Stock] set Amount=(Amount-@TT) where ItemID=1", Con, Trans)
                CMD14.Parameters.AddWithValue("@TT", v * txtAmount.Text)

                Dim CMD15 As New OleDb.OleDbCommand("Select Amount from [Recipes] where RecipeID=8", Con, Trans)
                Dim a = CMD15.ExecuteScalar()
                Dim CMD16 As New OleDb.OleDbCommand("Update [Stock] set Amount=(Amount-@TT) where ItemID=2", Con, Trans)
                CMD16.Parameters.AddWithValue("@TT", a * txtAmount.Text)

                Dim CMD17 As New OleDb.OleDbCommand("Select Amount from [Recipes] where RecipeID=9", Con, Trans)
                Dim b = CMD17.ExecuteScalar()
                Dim CMD18 As New OleDb.OleDbCommand("Update [Stock] set Amount=(Amount-@TT) where ItemID=104", Con, Trans)
                CMD18.Parameters.AddWithValue("@TT", b * txtAmount.Text)

                ' execute the command
                CMD2.ExecuteNonQuery()
                CMD4.ExecuteNonQuery()
                CMD6.ExecuteNonQuery()
                CMD8.ExecuteNonQuery()
                CMD10.ExecuteNonQuery()
                CMD12.ExecuteNonQuery()
                CMD14.ExecuteNonQuery()
                CMD16.ExecuteNonQuery()
                CMD18.ExecuteNonQuery()

                ' save the changes
                Trans.Commit()

                'Close connection
                Con.Close()

            End If
 On Error GoTo SaveErr
        InterimStorageOrdersBindingSource1.EndEdit()
        Interim_Storage_OrdersTableAdapter.Update(Stock_ManagerDataSet.Interim_Storage_Orders)
        MessageBox.Show("Entry Saved")
SaveErr:
        Exit Sub

删除按钮

If cmbProduct.Text = "100LB Saltbread" Then
            ' Open the db connection
            Dim Con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\Stock Manager.accdb")
            Con.Open()

            ' Start Transaction
            Dim Trans = Con.BeginTransaction

            'define a comand for the sql statement
            Dim CMD As New OleDb.OleDbCommand("SELECT Amount FROM [Recipes] WHERE RecipeID=1", Con, Trans)
            Dim i = CMD.ExecuteScalar()
            Dim CMD2 As New OleDb.OleDbCommand("Update [Stock] set Amount=(Amount+@TT) where ItemID=10", Con, Trans)
            CMD2.Parameters.AddWithValue("@TT", i * txtAmount.Text)


            Dim CMD3 As New OleDb.OleDbCommand("SELECT Amount FROM [Recipes] WHERE RecipeID=2", Con, Trans)
            Dim q = CMD3.ExecuteScalar()
            Dim CMD4 As New OleDb.OleDbCommand("Update [Stock] set Amount=(Amount+@TT) where ItemID=22", Con, Trans)
            CMD4.Parameters.AddWithValue("@TT", q * txtAmount.Text)

            Dim CMD5 As New OleDb.OleDbCommand("Select Amount from [Recipes] where RecipeID=3", Con, Trans)
            Dim w = CMD5.ExecuteScalar()
            Dim CMD6 As New OleDb.OleDbCommand("Update [Stock] set Amount=(Amount+@TT) where ItemID=21", Con, Trans)
            CMD6.Parameters.AddWithValue("@TT", w * txtAmount.Text)

            Dim CMD7 As New OleDb.OleDbCommand("Select Amount from [Recipes] where RecipeID=4", Con, Trans)
            Dim r = CMD7.ExecuteScalar()
            Dim CMD8 As New OleDb.OleDbCommand("Update [Stock] set Amount=(Amount+@TT) where ItemID=85", Con, Trans)
            CMD8.Parameters.AddWithValue("@TT", r * txtAmount.Text)

            Dim CMD9 As New OleDb.OleDbCommand("Select Amount from [Recipes] where RecipeID=5", Con, Trans)
            Dim d = CMD9.ExecuteScalar()
            Dim CMD10 As New OleDb.OleDbCommand("Update [Stock] set Amount=(Amount+@TT) where ItemID=8", Con, Trans)
            CMD10.Parameters.AddWithValue("@TT", d * txtAmount.Text)

            Dim CMD11 As New OleDb.OleDbCommand("Select Amount from [Recipes] where RecipeID=6", Con, Trans)
            Dim g = CMD11.ExecuteScalar()
            Dim CMD12 As New OleDb.OleDbCommand("Update [Stock] set Amount=(Amount+@TT) where ItemID=107", Con, Trans)
            CMD12.Parameters.AddWithValue("@TT", g * txtAmount.Text)

            Dim CMD13 As New OleDb.OleDbCommand("Select Amount from [Recipes] where RecipeID=7", Con, Trans)
            Dim v = CMD13.ExecuteScalar()
            Dim CMD14 As New OleDb.OleDbCommand("Update [Stock] set Amount=(Amount+@TT) where ItemID=1", Con, Trans)
            CMD14.Parameters.AddWithValue("@TT", v * txtAmount.Text)

            Dim CMD15 As New OleDb.OleDbCommand("Select Amount from [Recipes] where RecipeID=8", Con, Trans)
            Dim a = CMD15.ExecuteScalar()
            Dim CMD16 As New OleDb.OleDbCommand("Update [Stock] set Amount=(Amount+@TT) where ItemID=2", Con, Trans)
            CMD16.Parameters.AddWithValue("@TT", a * txtAmount.Text)

            Dim CMD17 As New OleDb.OleDbCommand("Select Amount from [Recipes] where RecipeID=9", Con, Trans)
            Dim b = CMD17.ExecuteScalar()
            Dim CMD18 As New OleDb.OleDbCommand("Update [Stock] set Amount=(Amount+@TT) where ItemID=104", Con, Trans)
            CMD18.Parameters.AddWithValue("@TT", b * txtAmount.Text)

            ' execute the command
            CMD2.ExecuteNonQuery()
            CMD4.ExecuteNonQuery()
            CMD6.ExecuteNonQuery()
            CMD8.ExecuteNonQuery()
            CMD10.ExecuteNonQuery()
            CMD12.ExecuteNonQuery()
            CMD14.ExecuteNonQuery()
            CMD16.ExecuteNonQuery()
            CMD18.ExecuteNonQuery()

            ' save the changes
            Trans.Commit()

            'Close connection
            Con.Close()

        End If
    InterimStorageOrdersBindingSource1.RemoveCurrent

1 个答案:

答案 0 :(得分:0)

Me.Stock_ManagerDataSet.Interim_Storage_Orders.AcceptChanges()

我将这行代码添加到我的保存按钮,它修复了问题:D