Knight Data Access Layer
RollbackTransaction Method (IDataHelper)
Example 




KellermanSoftware.NetDataAccessLayer Namespace > IDataHelper Interface : RollbackTransaction Method
Perform a rollback of the current transaction
Syntax
Sub RollbackTransaction() 
Dim instance As IDataHelper
 
instance.RollbackTransaction()
void RollbackTransaction()
void RollbackTransaction(); 
void RollbackTransaction(); 
Example
//Get the current thread static safe instance of the helper
IDataHelper db = DataHelper.SessionFactory();
 
//Specify User Name and License Key from the receipt, leave blank for trial mode
//db.UserName = "John Smith 1234";
//db.LicenseKey = "asdfl219==";
 
//Log to the console
db.EnableLogging();
 
//Fill in the maintenance Fields
db.FillInMaintenanceFields = true;
 
//Open the database connection
db.OpenConnection();
 
//Make sure all are deleted
db.ExecuteNonQuery("DELETE FROM PERSONS");
 
//Begin a transaction to save two people at once
 
db.BeginTransaction();
 
//Create a new Person to save to the database
Person person1 = new Person();
person1.FirstName = "John";
person1.LastName = "Smith";
 
//Save it to the database (see the SQL in the console)
db.Save(person1);
 
//Create another new Person to save to the database
Person person2 = new Person();
person2.FirstName = "Jane";
person2.LastName = "Smith";
 
//Save it to the database (see the SQL in the console)
db.Save(person2);
 
//Get the current transaction and print out some info
Console.WriteLine(db.Transaction.Connection.ConnectionString);
 
//Rollback the transaction
db.RollbackTransaction();
 
List<Person> persons = db.LoadAll<Person>();
 
Console.WriteLine(persons.Count);
 
//Close the connection
db.CloseConnection();
'Get the current thread static safe instance of the helper
Dim db As IDataHelper = DataHelper.SessionFactory()
 
'Specify User Name and License Key from the receipt, leave blank for trial mode
'db.UserName = "John Smith 1234"
'db.LicenseKey = "asdfl219=="
 
'Log to the console
db.EnableLogging()
 
'Fill in the maintenance Fields
db.FillInMaintenanceFields = True
 
'Open the database connection
db.OpenConnection()
 
'Make sure all are deleted
db.ExecuteNonQuery("DELETE FROM PERSONS")
 
'Begin a transaction to save two people at once
 
db.BeginTransaction()
 
'Create a new Person to save to the database
Dim person1 As New Person()
person1.FirstName = "John"
person1.LastName = "Smith"
 
'Save it to the database (see the SQL in the console)
db.Save(person1)
 
'Create another new Person to save to the database
Dim person2 As New Person()
person2.FirstName = "Jane"
person2.LastName = "Smith"
 
'Save it to the database (see the SQL in the console)
db.Save(person2)
 
'Get the current transaction and print out some info
Console.WriteLine(db.Transaction.Connection.ConnectionString)
 
'Rollback the transaction
db.RollbackTransaction()
 
Dim persons As List(Of Person) = db.LoadAll(Of Person)()
 
Console.WriteLine(persons.Count)
 
'Close the connection
db.CloseConnection()
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

IDataHelper Interface
IDataHelper Members