日期:2014-05-18 浏览次数:20887 次
public static bool OperateDatasWithTransaction(List<string> sqlList) { OracleConnection myConnection = new OracleConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnStrOrcl"]); myConnection.Open(); OracleCommand myCommand = myConnection.CreateCommand(); OracleTransaction myTrans; // Start a local transaction myTrans = myConnection.BeginTransaction(IsolationLevel.ReadCommitted); // Assign transaction object for a pending local transaction myCommand.Connection = myConnection; myCommand.Transaction = myTrans; try { foreach (string item in sqlList) { myCommand.CommandText = item; myCommand.ExecuteNonQuery(); } myTrans.Commit(); return true; } catch (Exception) { myTrans.Rollback(); return false; } finally { myConnection.Close(); }