// 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);
con.Open();
//Create an OracleCommand object using the connection object
OracleCommand cmd = new OracleCommand("", con);
// Start a transaction
OracleTransaction txn = con.BeginTransaction(IsolationLevel.ReadCommitted);
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.");
}
...