<% option explicit %>
<html>
<head>
<title>事物处理示例</title>
</head>
<body>
<%
Dim cnn,strConn,strsqla,strsqlb,strsql1
dim strsql2,monyea,monyeb,rsa,rsb
	strconn="dbq="&server.MapPath("bank.mdb")& _
	";driver={microsoft access driver (*.mdb)}"
	Set cnn=Server.CreateObject("ADODB.Connection") 
	cnn.Open strConn
	cnn.begintrans '开始事物处理
	strsqla="select sum(贷方)-sum(借方)"& _ 
	"from daybook where 帐户号='00001'"
	set rsa=cnn.execute(strsqla)
	monyea=rsa(0)    '获取帐户号='00001'的余额
	'rsa.close
	'set rsa=nothing
	strsqlb="select sum(贷方)-sum(借方)"& _
	"from daybook where 帐户号='00002'"
	set rsb=cnn.execute(strsqlb)
	monyeb=rsb(0)   '获取帐户号='00002'的余额
	rsb.close
	set rsb=nothing
	StrSql1="Insert Into daybook(帐户号,借方,余额,交易日期)"& _ 
	"Values('00001',200,"&monyea-200&",#"&date()&"#)" 
	cnn.Execute(strSql1)
	StrSql2="Insert Into daybook(帐户号,贷方,余额,交易日期)"& _
	"Values('00002',200,"&monyeb+200&",#"&date()&"#)" 
	cnn.Execute(strSql2)
	if cnn.errors.count>0 then
	cnn.errors.clear
	cnn.rollbacktrans '撤消事物处理
	response.Write "转帐不成功。"
	else
	cnn.committrans '提交事物处理
	response.Write "转帐成功。"
	end if
	cnn.close
	set cnn=nothing
	%>
</body>
</html>
