Knight Data Access Layer
IsInTransaction Property (DataHelper)
Example 




KellermanSoftware.NetDataAccessLayer Namespace > DataHelper Class : IsInTransaction Property
Returns true if we are in a transaction
Syntax
Public Overridable ReadOnly Property IsInTransaction As Boolean
Dim instance As DataHelper
Dim value As Boolean
 
value = instance.IsInTransaction
public virtual bool IsInTransaction {get;}
public: __property virtual bool get_IsInTransaction();
public:
virtual property bool IsInTransaction {
   bool 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);
 
//This will be true
Console.WriteLine(db.IsInTransaction);
 
//Commit the transaction
db.CommitTransaction();
 
//This will be false
Console.WriteLine(db.IsInTransaction);
 
//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)
 
'This will be true
Console.WriteLine(db.IsInTransaction)
 
'Commit the transaction
db.CommitTransaction()
 
'This will be false
Console.WriteLine(db.IsInTransaction)
 
'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