我正在尝试将我的textedit值存储到MS Access数据库,但我收到的错误是“查询值和目标字段的数量不相同”。但我的查询值和目标字段是相同的。我尝试在两种方法中插入同样的错误。
我先试过这个方法
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();
第二种方法
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);
在两种方法中获得相同的错误?我的代码有什么问题?帮帮我
答案 0 :(得分:1)
"WholeDiscountP,WholeDiscountA,ShippingP,ShippingA".
因此,当您的列名称正确时,列数会减一。