如何在我的情况下使用commit和rollback语句? [英] How to use commit and rollback statement in my situation?
本文介绍了如何在我的情况下使用commit和rollback语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
i我正在使用try-catch来捕获异常,我的代码是这样的:
Hello,
i am using using try-catch for catching the exception, my code is something like this:
try
{
sqlcommand cmd=new sqlcommand("insert into tablenm values(1,'abc')");
cmd.ExecuteNonQuery();
}
catch(Exception eli)
{
//some message
}
i想知道如果发生任何异常,我怎么能在sql命令之上回滚。
我尝试过:
i认为我可以在catch块中使用commit和rollback,我不确定这个
我是对的吗?
i want to know that how can i rollback above sql command if any exception occurs.
What I have tried:
i think i can use commit and rollback in catch block, i am not sure about this
am i right?
推荐答案
使用 SqlTransaction类(System.Data) .SqlClient) [ ^ ] - 此链接包含一个示例。
Use the SqlTransaction Class (System.Data.SqlClient)[^] - this link includes an example.
这篇关于如何在我的情况下使用commit和rollback语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文