Transaction

xiaoxiao2021-03-06  67

. // Starts a transaction and inserts one record If insert fails, rolls back // the transaction Otherwise, commits the transaction .... string ConStr =. "User Id = myschema; Password = mypassword;" "Data Source = oracle "

OracleConnection Con = New OracleConnection (Constr);

C.Open ();

// Create An OracleCommand Object Using The Connection ObjectOracleCommand CMD = New OracleCommand ("", CON);

// Start a transactionoracletransaction txn = con.begintransaction; try {cmd.commandtext = "INSERT INTO MyTable Values ​​(99, 'foo')"

cmd.commandtype = commandtype.text;

cmd.executenonquery ();

Txn.commit ();

Console.writeline ("Both Records Are INSERTED INTO The Database TABLE.")

} catch (exception e) {

Txn.rollback ();

Console.writeline ("Neither Record Was Inserted Into The Database Table.");

}

转载请注明原文地址:https://www.9cbs.com/read-90531.html

New Post(0)