INSERT SQL Updatable Query using proper MS Access cmd Command

71 Views Asked by At

Access databse query fails when i run on another machine Config Below

Microsoft Word 2013 Visual Studio 2013 Windows 8.1 (64 bit)

While On The Another Machine The Same Query Runs Config Below

Microsoft Word 2010 Visual Studio 2010 Windows 7 (32 bit)

The Query Below

 con.Open();

            string cb = "insert Into Salcmd = new sqles(InvoiceNo,InvoiceDate,CustomerID,SubTotal,VATPercentage,VATAmount,GrandTotal,TotalPayment,PaymentDue,Remarks) VALUES ('" + txtInvoiceNo.Text + "',#" + dtpInvoiceDate.Text + "#,'" + txtCustomerID.Text + "'," + txtSubTotal.Text + "," + txtTaxPer.Text + "," + txtTaxAmt.Text + "," + txtTotal.Text + "," + txtTotalPayment.Text + "," + txtPaymentDue.Text + ",'" + txtRemarks.Text + "')";
            cmd = new OleDbCommand(cb);
            cmd.Connection = con;
            cmd.ExecuteReader();
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
            con.Close();

is there something wrong with the Query Dependencies Please Let Me Know

1

There are 1 best solutions below

2
On BEST ANSWER

You INSERT SQL statement contains a syntax error:

string cb = "insert Into Salcmd = new sqles(InvoiceNo,InvoiceDate,CustomerID,SubTotal,VATPercentage,VATAmount,GrandTotal,TotalPayment,PaymentDue,Remarks) VALUES ('" + txtInvoiceNo.Text + "',#" + dtpInvoiceDate.Text + "#,'" + txtCustomerID.Text + "'," + txtSubTotal.Text + "," + txtTaxPer.Text + "," + txtTaxAmt.Text + "," + txtTotal.Text + "," + txtTotalPayment.Text + "," + txtPaymentDue.Text + ",'" + txtRemarks.Text + "')"

It possibly should be:

string cb = "INSERT INTO sqles(InvoiceNo,InvoiceDate,CustomerID,SubTotal,VATPercentage,VATAmount,GrandTotal,TotalPayment,PaymentDue,Remarks) VALUES ('" + txtInvoiceNo.Text + "',#" + dtpInvoiceDate.Text + "#,'" + txtCustomerID.Text + "'," + txtSubTotal.Text + "," + txtTaxPer.Text + "," + txtTaxAmt.Text + "," + txtTotal.Text + "," + txtTotalPayment.Text + "," + txtPaymentDue.Text + ",'" + txtRemarks.Text + "')"

Also, try: cmd.ExecuteNonQuery() instead of reader.

Hope this may help.