using (OracleConnection connection = new OracleConnection(connectionString)) { connection.Open(); OracleTransaction transaction = connection.BeginTransaction(); try { //執行一些操作 transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); Console.WriteLine("Error occurred: " + ex.Message); } }在上面的代碼中,我們首先使用
using (OracleConnection connection = new OracleConnection(connectionString)) { connection.Open(); OracleTransaction transaction = connection.BeginTransaction(); try { //第一層操作 OracleTransaction transaction1 = connection.BeginTransaction(); try { //第二層操作 transaction1.Commit(); } catch (Exception ex) { transaction1.Rollback(); Console.WriteLine("Error occurred: " + ex.Message); } //第一層操作 transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); Console.WriteLine("Error occurred: " + ex.Message); } }在上面的代碼中,我們使用
using (OracleConnection connection = new OracleConnection(connectionString)) { connection.Open(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { //執行一些操作 scope.Complete(); } }在上面的代碼中,我們使用