sqlhelper 实现回滚事务

SqlConnection con = new SqlConnection(SqlHelper.yfConString);
con.Open();
SqlTransaction tran = con.BeginTransaction();

try

{

 SqlHelper.ExecuteNonQuery(tran, CommandType.Text, sb.ToString(), par);

SqlHelper.ExecuteNonQuery(tran, CommandType.Text, sb1.ToString(), par);

SqlHelper.ExecuteNonQuery(tran, CommandType.Text, sb2.ToString(), par);

SqlHelper.ExecuteNonQuery(tran, CommandType.Text, sb3.ToString(), par);
tran.Commit();

}

catch

{

tran.Rollback();

}

 finally
{

 if(con.State==ConnectionState.Open)

{
 con.Open();

}
 }

posted on 2011-01-11 16:51  AlexGeng  阅读(1804)  评论(0编辑  收藏  举报

导航