C#中使用MS Access的标准表达式中的数据类型不匹配?

嗨,我尝试将数据从我的表单保存到MS Access数据库。 有13个字段要保存,但是当我点击此行显示的保存按钮错误时top.ExecuteNonQuery(); Data type mismatch in criteria expression

这是我的代码尽可能帮助我

  OleDbConnection conn = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:/Srihari/Srihari/Invoice.accdb"); conn.Open(); // to save top column in invoive 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; bool inclusive = CBX_New.Checked; decimal Price = Convert.ToDecimal(TXE_Price.Text); decimal tax = Convert.ToDecimal(TXE_Tax.Text); decimal grandtotal = Convert.ToDecimal(TXE_Total.Text); OleDbCommand top = new OleDbCommand("INSERT INTO test_top(InvoiceNumber,Terms,[InvoiceDate],OurQuote,SalesPerson,CustomerName,OrderNumber,InvoiceAddress,DeliveryAddress,InclusiveStatus,Price,Tax,GrandTotal) VALUES (" + invoicenumber + ",'" + terms + "','" + date + "','" + ourquote + "','" + salesperson + "','" + customername + "','" + oderno + "','" + invoiceaddress + "','" + deliveryaddress + "','" + inclusive + "','" + Price + "','" + tax + "','" + grandtotal + "')", conn); top.ExecuteNonQuery(); MessageBox.Show("Inserted Successful (top)", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); 

conn.close();

在Access数据库13列InvoiceNumber编号,术语文本,InvoiceDate日期/时间,OurQuote文本,SalesPerson文本,CustomerName文本,Orderno文本,InvoiceAddress备忘录,DeliveryAddress备注,InclusiveStatus是/否,价格十进制,税十进制,GrandTotal十进制。

我的代码出了什么问题?

说真的,通过使用参数查询来节省头痛并同时编写更可靠的代码:

 OleDbCommand top = new OleDbCommand( "INSERT INTO test_top (" + "InvoiceNumber,Terms,[InvoiceDate],OurQuote," + "SalesPerson,CustomerName,OrderNumber," + "InvoiceAddress,DeliveryAddress,InclusiveStatus," + "Price,Tax,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("?", inclusive); top.Parameters.AddWithValue("?", Price); top.Parameters.AddWithValue("?", tax); top.Parameters.AddWithValue("?", grandtotal); top.ExecuteNonQuery(); 

在保存到Access Database时,我认为您应该知道的几点

1) String应在single Quotes

2) Numeric值不应在引号内

3)应使用保存DateTime