vb.net 如何执行事务?
声明的参数
declare
@CardID int ,
@StudentNo Char(11),
@AddMoney int ,
@Date Char(11),
@Time Char(11),
@UserID Char(10)
更新学生金额
UPDATE TB_Student_Info SET Cash =Cash +@AddMoney WHERE CardID = @CardID
插入到充值记录表中
INSERT INTO TB_Recharge_Info VALUES(@CardID, @StudentNo,@AddMoney,@Date,@Time,@UserID)
要求:
当我更新学生表的金额时,将学生的充值记录添加到充值表中,不使用存储过程,而是适用SQL Sever 中的事务怎么通过vb.net 实现?参数是从vb.net 中获取的 sql?sever??事务 vb.net与SQL交互
[解决办法]
给你个帖子http://developer.51cto.com/art/201001/178012.htm
[解决办法]
Dim sql As String
Dim item As RepeaterItem
Dim cn As New SqlClient.SqlConnection(P_ConnectString)
Dim cmd As New SqlClient.SqlCommand
Dim tran As SqlClient.SqlTransaction
Dim tbl As New DataTable
cn.Open()
cmd.Connection = cn
tran = cn.BeginTransaction
cmd.Transaction = tran
。。
。。
。。
tran.Commit()
set @CardID='';
set @StudentNo='';
set @AddMoney='';
set @Date='';
set @Time='';
set @UserID='';
UPDATE TB_Student_Info SET Cash =Cash +@AddMoney WHERE CardID = @CardID
INSERT INTO TB_Recharge_Info VALUES(@CardID, @StudentNo,@AddMoney,@Date,@Time,@UserID)
END
exec [TEST]
GO
[解决办法]