首页 > 代码库 > ASP.NET中调用事务处理的方法

ASP.NET中调用事务处理的方法

/// <summary>       ///   事务处理        /// </summary>       /// <param name="strSql"></param>       /// <returns></returns>       public bool InportData(string strSql)       {                      SqlConnection sqlConnection = new SqlConnection(DbHelperSQL.connectionString);           sqlConnection.Open();           SqlTransaction myTrans = sqlConnection.BeginTransaction();           SqlCommand sqlInsertCommand = new SqlCommand();           sqlInsertCommand.Connection = sqlConnection;           sqlInsertCommand.Transaction = myTrans;           try           {               sqlInsertCommand.CommandText = strSql.ToString();               sqlInsertCommand.ExecuteNonQuery();               myTrans.Commit();               return true;           }           catch (Exception ex)           {               myTrans.Rollback();               return false;           }           finally           {               sqlConnection.Close();           }       }

  

ASP.NET中调用事务处理的方法