在C#中使用MSAccess的标准表达式中的数据类型不匹配?您好我尝试将数据从我的表单保存到MSAccess数据库。有13个字段要保存,但是当我单击保存按钮时,此行显示错误top.ExecuteNonQuery();条件表达式中的数据类型不匹配。这是我的代码尽管可能帮助我OleDbConnectionconn=newOleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;DataSource=D:/Srihari/Srihari/Invoice.accdb");conn.Open();//保存invoive中的顶部列intinvoicenumber=Convert.ToInt32(TXE_Invoice_Number.Text);字符串术语=CBL_Terms.Text;DateTimedate=CBL_Date.DateTime;stringourquote=TXE_OurQuote.Text;stringsalesperson=CBL_Sales_Person.Text;stringcustomername=CBL_Customer_Nmae.Text;stringoderno=CBL_Order_Number.Text;stringinvoiceaddress=TXE_Invoice_Address.Text;stringdeliveryaddress=TXE_Delivery_Address.Text;boolinclusive=CBX_New.Checked;十进制价格=Convert.ToDecimal(TXE_Price.Text);十进制税=Convert.ToDecimal(TXE_Tax.Text);小数总计=Convert.ToDecimal(TXE_Total.Text);OleDbCommandtop=newOleDbCommand("INSERTINTOtest_top(InvoiceNumber,Terms,[InvoiceDate],OurQuote,SalesPerson,CustomerName,OrderNumber,InvoiceAddress,DeliveryAddress,InclusiveStatus,Price,Tax,GrandTotal)VALUES("+invoicenumber+",'"+terms+"','"+date+"','"+ourquote+"','"+salesperson+"','"+customername+"','"+oderno+"','"+发票地址+"','"+送货地址+"','"+包含+"','"+价格+"','"+税费+"','"+grandtotal+"')",conn);top.ExecuteNonQuery();MessageBox.Show("插入成功(top)","Information",MessageBoxButtons.OK,MessageBoxIcon.Information);conn.close();在Access数据库中13列InvoiceNumberNumber,TermText,InvoiceDateDate/Time,OurQuoteText,SalesPersonText,CustomerNameText,OrdernoText,InvoiceAddressMemo,DeliveryAddressRemarks,InclusiveStatusYes/No,PriceDecimal,TaxDecimal,GrandTotalDecimal我的代码有什么问题?说真的,通过使用参数查询,让自己省去麻烦并同时编写更可靠的代码:OrderNumber,"+"InvoiceAddress,DeliveryAddress,InclusiveStatus,"+"Price,Tax,GrandTotal"+")VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)",连接);top.Parameters.AddWithValue("?",invoicenumber);top.Parameters.AddWithValue("?",术语);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("?",送货地址);top.Parameters.AddWithValue("?",inclusive);top.Parameters.AddWithValue("?",价格);顶部.Parameters.AddWithValue("?",tax);top.Parameters.AddWithValue("?",grandtotal);top.ExecuteNonQuery();保存到Access数据库时,我想你应该知道的几点1)字符串应该用单引号2)数值不应该用引号3)DateTime值应该使用#Typemismatch来保存?分享的所有内容,如果对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如有转载请注明出处:
