ADO.NET 事务处理

在传统的ADO.NET中使用事务,方法如下:

复制代码

    Execute( connectionString)
 {
      (SqlConnection connection =  SqlConnection(connectionString))
     {
         connection.Open();
 
         SqlCommand command = connection.CreateCommand();
         SqlTransaction transaction;
 
                  transaction = connection.BeginTransaction();
 
                  command.Connection = connection;
         command.Transaction = transaction;
 
         
         {
             command.CommandText =;
             command.ExecuteNonQuery();
         
                          transaction.Commit();
             ......
         }
          (Exception ex)
         {
                          transaction.Rollback();
             .....
         }
     }
 }


你可能感兴趣的:(sql,事务处理)