[Visual Basic]
Public Sub RunSqlCeTransaction(myConnString As String)
Dim myConnection As New SqlCeConnection(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
转载于:https://www.cnblogs.com/qiyuan/archive/2006/09/12/501933.html