【发布时间】:2015-02-09 08:43:20
【问题描述】:
我使用此命令在多行中插入多条记录,如果插入不成功,如何锁定我的命令并回滚更改?
SqlCommand cmd = new SqlCommand();
string s = @"
declare @one_id int;
INSERT INTO tbl_one(o1,o2,o3) VALUES(@o1,@o2,@o3);
set @one_id=SCOPE_IDENTITY();
INSERT INTO tbl_two(t1,t2,f3) VALUES(@t1,@t2,@one_id);
INSERT INTO tbl_two(t1,t2,f3) VALUES(@t3,@t4,@one_id);
INSERT INTO tbl_two(t1,t2,f3) VALUES(@t5,@t6,@one_id);
";
cmd.CommandText =s;
【问题讨论】:
标签: sql asp.net sql-server transactions locking