这在 vb.net 中是否可行
sub Main()
conn.open
transactions = conn.begintransaction("SAMPLE")
insertintotable1()
insertintotable2()
insertintotable3()
transactions.commit
end sub
sub insertintotable1
try
conn = new sql connection(connectionstring)
strsql = sql statement
cmd = new sql command(strsql, conn)
cmd.executenonquery
catch ex as exception
transaction.rollback
end try
end sub
sub insertintotable2
try
conn = new sql connection(connectionstring)
strsql = sql statement
cmd = new sql command(strsql, conn)
cmd.executenonquery
catch ex as exception
transaction.rollback
end try
end sub
sub insertintotable3
try
conn = new sql connection(connectionstring)
strsql = sql statement
cmd = new sql command(strsql, conn)
cmd.executenonquery
catch ex as exception
transaction.rollback
end try
end sub
我的问题是,如果我在第二个表中的查询有问题,那么如果没有事务,则表 1 的数据已经被插入。所以我查找了事务,理论上它会解决这个问题,因为如果出现故障,你可以回滚插入。