Knight Data Access Layer
Transaction Property (DataHelper)
Example 




KellermanSoftware.NetDataAccessLayer Namespace > DataHelper Class : Transaction Property
Get a reference to the current transaction
Syntax
Public Overridable ReadOnly Property Transaction As IDbTransaction
Dim instance As DataHelper
Dim value As IDbTransaction
 
value = instance.Transaction
public virtual IDbTransaction Transaction {get;}
public: __property virtual IDbTransaction* get_Transaction();
public:
virtual property IDbTransaction^ Transaction {
   IDbTransaction^ get();
}
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();
 
//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);
 
//Commit the transaction
db.CommitTransaction();
 
//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()
 
'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)
 
'Commit the transaction
db.CommitTransaction()
 
'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

DataHelper Class
DataHelper Members