![ContractedBlock.gif](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![ExpandedBlockStart.gif](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
SqlTransaction tran;
tran = con.BeginTransaction();
SqlCommand cmd1 = new SqlCommand(cmdText1);
cmd1.Connection = con;
cmd1.Transaction = tran;
…
SqlCommand cmd2 = new SqlCommand(cmdText2);
cmd2.Connection = con;
cmd2.Transaction = tran;
…
try{
cmd1.ExecuteNonQuery();
cmd2.ExecuteNonQuery();
tran.Commit();
}catch{
tran.Rollback();
}finally{
con.Close();
}