VB.NET编程语言主要是面向对象,并且可以为开发人员提供一个稳固安全的编程框架。在使用的过程中就会发现其特有的性质可以为我们带来轻松的代码编写。在这里就先从VB.NET事务处理来对此进行一个解读。#t#
VB.NET事务处理代码示例:
- [Visual Basic]
- Public Sub RunSqlCeTransaction
(myConnString As String) - Dim myConnection As New SqlCe
Connection(myConnString) - myConnection.Open()
- Dim myCommand As New SqlCeCommand()
- Dim myTrans As SqlCeTransaction
- ' Start a local transaction
- myTrans = myConnection.BeginTransaction()
- ' Must assign both transaction object
and connection - ' to Command object for a pending
local transaction - myCommand.Connection = myConnection
- myCommand.Transaction = myTrans
- Try
- myCommand.CommandText = "Insert into
Region (RegionID, RegionDescription)
VALUES (100, 'Description')" - myCommand.ExecuteNonQuery()
- myCommand.CommandText = "Insert into
Region (RegionID, RegionDescription)
VALUES (101, 'Description')" - myCommand.ExecuteNonQuery()
- myTrans.Commit()
- Catch
- Try
- myTrans.Rollback()
- Catch e As SqlCeException
- ' Handle possible exception here
- End Try
- Finally
- myConnection.Close()
- End Try
- End Sub
VB.NET事务处理相关代码编写方式就为大家介绍到这里。