时间:2021-07-01 10:21:17 帮助过:2人阅读
1、 OracleTransaction类的概述(from msdn )
应用程序通过针对OracleConnection对象调用 BeginTransaction 来创建OracleTransaction对象。对OracleTransaction对象执行与该事务关联的所有后续操作(例如提交或中止该事务)。 示例 OracleTransaction的成员主要有: 属性: Connection,指定与该事务关联的OracleConnection对象; IsolationLevel,指定该事务的IsolationLevel;枚举类型,用于对事物的锁定,取值有Chaos、ReadCommited、 ReadUncommited、RepeatableRead、Serializable、Unspecified。 方法: Commit,提交SQL数据库事务; Rollback , 从挂起状态回滚事务;
try
{
myCommand.CommandText = "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, ‘TECHNOLOGY‘, ‘DENVER‘)";
myCommand.ExecuteNonQuery();
myCommand.CommandText = "INSERT INTO Dept (DeptNo, Dname, Loc) values (60, ‘ENGINEERING‘, ‘KANSAS CITY‘)";
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 was written to database.");
}
finally
{
myConnection.Close();
}
}
C#中使用OracleTransaction
标签: