Hi, am trying to store my textedit valued to MS Access Database but am getting error like this "Number of query values and destination fields are not the same". But my query values and destination fields are same. I try to inserting in two methods both method getting same error.
I tried this method first
int invoicenumber = Convert.ToInt32(TXE_Invoice_Number.Text);
string terms = CBL_Terms.Text;
DateTime date = CBL_Date.DateTime;
string ourquote = TXE_OurQuote.Text;
string salesperson = CBL_Sales_Person.Text;
string customername = CBL_Customer_Nmae.Text;
string oderno = CBL_Order_Number.Text;
string invoiceaddress = TXE_Invoice_Address.Text;
string deliveryaddress = TXE_Delivery_Address.Text;
decimal wholediscper = Convert.ToDecimal(TXE_FlatDiscountP.Text);
decimal wholediscamt = Convert.ToDecimal(TXE_FlatDiscountA.Text);
decimal shippingpercenatge = Convert.ToDecimal(TXE_ShippingPercentage.Text);
decimal shippingamount = Convert.ToDecimal(TXE_ShippingAmount.Text);
decimal unitprice = Convert.ToDecimal(TXE_SubTotal.Text);
decimal discount = Convert.ToDecimal(TXE_Discount.Text);
decimal tax = Convert.ToDecimal(TXE_Tax.Text);
decimal shiping = Convert.ToDecimal(TXE_Shipping.Text);
decimal grandtotal = Convert.ToDecimal(TXE_GrandTotal.Text);
OleDbCommand top = new OleDbCommand(
"INSERT INTO NewInvoice_1 (" +
"InvoiceNumber,Terms,[InvoiceDate],OurQuote," +
"SalesPerson,CustomerName,OrderNumber," +
"InvoiceAddress,DeliveryAddress," +
"WholeDiscountP,WholeDiscountA,ShippingP,ShippingA" +
"Price,Discount,Tax" +
"Shipping,GrandTotal" +
") VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", conn);
top.Parameters.AddWithValue("?", invoicenumber);
top.Parameters.AddWithValue("?", terms);
top.Parameters.AddWithValue("?", date);
top.Parameters.AddWithValue("?", ourquote);
top.Parameters.AddWithValue("?", salesperson);
top.Parameters.AddWithValue("?", customername);
top.Parameters.AddWithValue("?", oderno);
top.Parameters.AddWithValue("?", invoiceaddress);
top.Parameters.AddWithValue("?", deliveryaddress);
top.Parameters.AddWithValue("?", wholediscper);
top.Parameters.AddWithValue("?", wholediscamt);
top.Parameters.AddWithValue("?", shippingpercenatge);
top.Parameters.AddWithValue("?", shippingamount);
top.Parameters.AddWithValue("?", unitprice);
top.Parameters.AddWithValue("?", discount);
top.Parameters.AddWithValue("?", tax);
top.Parameters.AddWithValue("?", shiping);
top.Parameters.AddWithValue("?", grandtotal);
top.ExecuteNonQuery();
Second method
int invoicenumber = Convert.ToInt32(TXE_Invoice_Number.Text);
string terms = CBL_Terms.Text;
DateTime date = CBL_Date.DateTime;
string ourquote = TXE_OurQuote.Text;
string salesperson = CBL_Sales_Person.Text;
string customername = CBL_Customer_Nmae.Text;
string oderno = CBL_Order_Number.Text;
string invoiceaddress = TXE_Invoice_Address.Text;
string deliveryaddress = TXE_Delivery_Address.Text;
decimal wholediscper = Convert.ToDecimal(TXE_FlatDiscountP.Text);
decimal wholediscamt = Convert.ToDecimal(TXE_FlatDiscountA.Text);
decimal shippingpercenatge = Convert.ToDecimal(TXE_ShippingPercentage.Text);
decimal shippingamount = Convert.ToDecimal(TXE_ShippingAmount.Text);
decimal unitprice = Convert.ToDecimal(TXE_SubTotal.Text);
decimal discount = Convert.ToDecimal(TXE_Discount.Text);
decimal tax = Convert.ToDecimal(TXE_Tax.Text);
decimal shiping = Convert.ToDecimal(TXE_Shipping.Text);
decimal grandtotal = Convert.ToDecimal(TXE_GrandTotal.Text);
OleDbCommand top = new OleDbCommand("INSERT INTO test_top(InvoiceNumber,Terms,[InvoiceDate],OurQuote,SalesPerson,CustomerName,OrderNumber,InvoiceAddress,DeliveryAddress,WholeDiscountP,WholeDiscountA,ShippingP,ShippingA,Price,Discount,Tax,Shipping,GrandTotal) VALUES (" + invoicenumber + ",'" + terms + "','" + date + "','" + ourquote + "','" + salesperson + "','" + customername + "','" + oderno + "','" + invoiceaddress + "','" + deliveryaddress + "',"+ wholediscper +","+ wholediscamt +","+ shippingpercenatge +","+ shippingamount +"," + unitprice + "," + tax + "," + grandtotal + ")", conn);
In Both method getting same error ? Whats wrong with my code ? Help me