插入语句错误我不能将我的数据保存到接收Db [英] Insert Into Statement Error I Cant Save My Data In To Accesess Db
本文介绍了插入语句错误我不能将我的数据保存到接收Db的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Dim CMD3 As New OleDb.OleDbCommand
SQL = "insert into reciptdetails" +
"(Reciptid,Barcode,Itemcount,Itembuyprice,Itemsellprice)" +
"values" +
"(:0 ,:1 ,:2 ,:3 ,:4 )"
CMD3.Connection = Myconnection
CMD3.Transaction = Mytransaction
CMD3.CommandText = SQL
CMD3.Parameters.AddWithValue(":0", reciptid)
CMD3.Parameters.AddWithValue(":1", Barcode)
CMD3.Parameters.AddWithValue(":2", Itemcount)
CMD3.Parameters.AddWithValue(":3", BuyPrice)
CMD3.Parameters.AddWithValue(":4", SellPrice)
CMD3.ExecuteNonQuery()
CMD3.Dispose()
推荐答案
由于你正在使用一个交易,我会检查你已经承诺它的某个地方 - 如果你没有,那么你的更改可能会被丢弃。
如果不是这样,我们需要更多地了解你在做什么,以及你得到了什么错误!
Since you are using a Transaction, I'd check that somewhere you have Committed it - if you don't, then your changes may well be being discarded.
If it's not that, we need to know a lot more about what you are doing, and what errors you get!
要添加到解决方案1,因为你没有' t发布与此代码片段相关的所有代码,您应该处理的事情很少(除非已经处理过):
To add to Solution 1, since you didn't post all of the code related to this code fragment, few things you should take care of (unless already dealt with):
- Always use try..catch blocks to handle exceptions.
- instead of disposing the commands or connections, use Dispose[^] statement to ensure proper release of resources in all cases.
- It looks like you're storing the connection somewhere for a longer period of time. This is often not necessary and opening and closing the connection for each operation probably makes the code more robust.
- Also it looks like you're storing the transaction for a longer period of time. This shouldn't ever be done. Transaction is always specific to a single operation.
这篇关于插入语句错误我不能将我的数据保存到接收Db的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文