没有更新我的访问数据库

时间:2018-01-28 09:40:50

标签: c# mysql winforms ms-access

public void UpdateSales()
{
    OleDbConnection connect = new OleDbConnection();
        connect.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\rango\Documents\posisdb_ibra.accdb;
        Persist Security Info=False;";
        OleDbCommand command = new OleDbCommand(@"UPDATE Transactions SET VatAmount = VatAmount - @vat, NonVatTotal =NonVatTotal- @nonvat,  TotalAmount =TotalAmount- @totalam  WHERE InvoiceNo =@txt", connect);
        command.Connection = connect;
        command.Parameters.Add("@vat", OleDbType.Decimal).Value = Convert.ToDecimal(lblVAT.Text.Replace(",", ""));
        command.Parameters.Add("@nonvat", OleDbType.Decimal).Value = Convert.ToDecimal(lblSubTotal.Text.Replace(",", ""));
        command.Parameters.Add("@totalam", OleDbType.Decimal).Value = Convert.ToDecimal(lblTotalAmount.Text.Replace(",", ""));
        command.Parameters.Add("@txt", OleDbType.VarChar).Value = lblInvoice.Text;
 try
    {
        connect.Open(); // opting connection
    }
    catch (Exception expe)
    {
        //Interaction.MsgBox(expe.ToString());
        MessageBox.Show(expe.Source);
    }
    try
    {
        command.ExecuteNonQuery();

        MessageBox.Show("DATA UPDATED");
    }
    catch (Exception expe)
    {
        //Interaction.MsgBox(expe.ToString());
        MessageBox.Show(expe.Source);
    }
    finally
    {
        connect.Close(); // closing connection
    }
}

代码运行良好,没有错误,但它没有更新我的数据库已尝试所有选项可能是错误使用ms访问它应该减去数据库中的值

0 个答案:

没有答案