尝试“交易".首次...

编程入门 行业动态 更新时间:2024-10-12 01:22:01
本文介绍了尝试“交易".首次...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是我第一次尝试使用交易...只是想知道我是否正确"完成了?看来还可以,但这并不代表什么. 只是尝试从数据表更新Access数据库.

This is the first time I''ve tried using a transaction... just wondering if I have done it "right"? It seems to work ok, but that doesn''t mean anything. Just trying to update an Access database from a datatable.

objConn.openConnection() Dim myTrans As OleDbTransaction = objConn.con.BeginTransaction() Dim cmd As New OleDbCommand cmd.Connection = objConn.con cmd.Transaction = myTrans Dim tRow As DataRow Dim sql As String Try For Each tRow In table.Rows sql = String.Format("UPDATE Pricing SET unitPrice = {0}, salesPrice = {1}, ProfitMargin = {2} WHERE ItemID = {3}", tRow(1), tRow(2), tRow(3), tRow(0)) cmd.CommandText = sql cmd.ExecuteNonQuery() Next myTrans.Commit() MessageBox.Show("Update Complete", "Vending", MessageBoxButtons.OK, MessageBoxIcon.Information) Catch ex As Exception MessageBox.Show(ex.ToString & vbCrLf & "Un-doing any work that has been done!", "Vending", MessageBoxButtons.OK, MessageBoxIcon.Error) myTrans.Rollback() Finally objConn.closeConnection() End Try

推荐答案

这已正确实施.如果要测试事务,请至少有2个表要在其中插入数据,并在将数据插入1个表后调用异常.这将回滚数据,而您不会在表中插入部分数据.这就是实现事务时的期望. This is implemented properly. If you want to test transaction, have atleast 2 tables where you intend to insert data and invoke an exception after data in inserted in 1 table. That would rollback the data and you don''t get partial data inserted in tables. This is what you expect when you implement transaction.

更多推荐

尝试“交易".首次...

本文发布于:2023-11-27 15:00:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1638543.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:首次   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!