我操作数据库中的两个表,
先操作第一个表,然后根据第一个表的ID操作第二个表。
这两个操作都在不同的方法之中。
请问怎么进行事务处理?
http://www.lostinet.com/files/SqlScope.rar
在存储过程里:
set xact_abort on
begin transaction
commit transaction
you could share a connection among multi-entity,certainly,each data entity contain
relevant sql,and using SQlTransaction like what "qimini(循序渐进)",you will realize the function mts.
btw,the method impossible break the conceptual layered thinkings.
function1:
Dim conn As SqlConnection = New SqlConnection(strConn)
conn.Open()
Dim SqlDBCmd As New SqlCommand
SqlDBCmd.Connection = conn
dim sqlstring as string
sqlstring ="insert . . ."your insert string
sqlstring += "SELECT @@IDENTITY AS Identity
‘Returns the last-inserted identity value.
Dim sqlDBReader As SqlDataReader
Try
sqlDBReader = SqlDBCmd.ExecuteReader
If sqlDBReader.Read Then
viewstate("id") = sqlDBReader.Item(0)
End If
function2:
use viewstate("id") directly
在onInit或onPageLoad事件中开始事务,在Dispose或onUnload中提交事务。