Knight Data Access Layer
GetMaxPrimaryKey(String,String) Method
Example 




KellermanSoftware.NetDataAccessLayer Namespace > IDataHelper Interface > GetMaxPrimaryKey Method : GetMaxPrimaryKey(String,String) Method
The database table name
The name of the primary key for the table
Get the maximum value for a primary key.
Syntax
Overloads Function GetMaxPrimaryKey( _
   ByVal tableName As String, _
   ByVal primaryKey As String _
) As Long
Dim instance As IDataHelper
Dim tableName As String
Dim primaryKey As String
Dim value As Long
 
value = instance.GetMaxPrimaryKey(tableName, primaryKey)
long GetMaxPrimaryKey( 
   string tableName,
   string primaryKey
)
long GetMaxPrimaryKey( 
   string* tableName,
   string* primaryKey
) 
int64 GetMaxPrimaryKey( 
   String^ tableName,
   String^ primaryKey
) 

Parameters

tableName
The database table name
primaryKey
The name of the primary key for the table
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();
 
//Open the database connection
db.OpenConnection();
 
//Create a new Person to save to the database
Person currentPerson = new Person();
currentPerson.FirstName = "John";
currentPerson.LastName = "Smith";
 
//Save it to the database 
db.Save(currentPerson);
 
long maxPrimaryKey = db.GetMaxPrimaryKey("Persons","PersonId");
 
Console.WriteLine(maxPrimaryKey);
 
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()
 
'Open the database connection
db.OpenConnection()
 
'Create a new Person to save to the database
Dim currentPerson As New Person()
currentPerson.FirstName = "John"
currentPerson.LastName = "Smith"
 
'Save it to the database 
db.Save(currentPerson)
 
Dim maxPrimaryKey As Long = db.GetMaxPrimaryKey("Persons","PersonId")
 
Console.WriteLine(maxPrimaryKey)
 
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
Overload List