今天就跟大家聊聊有關(guān)VB.NET中怎么實現(xiàn)事務(wù)處理,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。
創(chuàng)新互聯(lián)建站主營武鳴網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,app軟件開發(fā),武鳴h5小程序開發(fā)搭建,武鳴網(wǎng)站營銷推廣歡迎武鳴等地區(qū)企業(yè)咨詢
VB.NET事務(wù)處理代碼示例:
[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
看完上述內(nèi)容,你們對VB.NET中怎么實現(xiàn)事務(wù)處理有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。