1. 怎样用事务(B/S)
1.1 .aspx文件的page声明部分加入 Transaction="Required"
如:<%@ Page Language="vb" Transaction="Required" AutoEventWireup="false" Codebehind="Order.aspx.vb" Inherits="EasyClick.Order" %>
1.2 在项目中引用\.Net\System.EnterpriseServices\
1.3 在后台文件中导入命名空间system.EnterpriseService
如:Imports System.EnterpriseServices
1.4 在数据提交的过程中应用事务。
如:
Try
…….
…….
’向数据库中成功写入数据
ContextUtil.SetComplete()’提交事务
Catch ex As Exception
Dim exm As String = ex.Message
ContextUtil.SetAbort()’事务回滚
End Try
1.5 添加事务处理过程。
如:
’事务提交处理过程
Private Sub Page_Commit(ByVal sender As System.Object, ByVal eArgs As System.EventArgs) Handles MyBase.CommitTransaction
If IsPostBack Then
Response.Redirect("../../aspx/success.aspx")
End If
End Sub
’事务回滚处理过程
Private Sub Page_Abort(ByVal sender As System.Object, ByVal eArgs As System.EventArgs) Handles MyBase.AbortTransaction
If IsPostBack Then
Response.Redirect("../../aspx/failpage.aspx")
End If
End Sub