事务的操作

 

       //事务
        using (SqlTransaction sqlTran = sqlgen.BeginTransaction)
        {
            
try
            {
                sqlgen.ExecuteNonQuery(sqlTran, 
"sql语句1");
                sqlgen.ExecuteNonQuery(sqlTran, 
"sql语句2");
                sqlTran.Commit();
            }
            
catch 
            {
                sqlTran.Rollback();            
            }
        }





      
#region BeginTransaction 开始一个事务
        
/// <summary>
        
/// 开始一个事务
        
/// </summary>
        
/// <returns>事务</returns>
        public SqlTransaction BeginTransaction()
        {
            SqlConnection c 
= new SqlConnection(conn);
            c.Open();
            
return c.BeginTransaction();
        }
        
#endregion
posted @ 2009-05-21 10:41  awp110  阅读(144)  评论(0编辑  收藏  举报