Data | Database The following example creates a OracleConnection and a oracletransaction. It also demonstrates how to use the BeginTransaction, Commit, and Rollback methods.
public void Runoracletransaction (String myconnstring)
{
OracleConnection myconnection = new OracleConnection (myConnString);
Myconnection.open ();
Start a local transaction
Mytrans = Myconnection.begintransaction (isolationlevel.readcommitted);
Assign transaction object for a pending local transaction
Mycommand.transaction = Mytrans;
Try
{
myCommand.CommandText = "INSERT into Dept (DeptNo, dname, Loc) VALUES (, ' TECHNOLOGY ', ' DENVER ')";
Mycommand.executenonquery ();
Mycommand.commandtype= CommandType.StoredProcedure;
mycommand.commandtext= "Prc_test";
Mycommand.executenonquery ();
Mytrans.commit ();
Console.WriteLine ("Both records are written to database.");
}
catch (Exception e)
{
Mytrans.rollback ();
Console.WriteLine (E.tostring ());
Console.WriteLine ("Neither record is written to database.");
}
Finally
{
Myconnection.close ();
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.