Knight Data Access Layer
Search<T>(T,String,Int32) Method
Example 




KellermanSoftware.NetDataAccessLayer Namespace > DataHelper Class > Search Method : Search<T>(T,String,Int32) Method
Generic class type
What to search for. Default values are not searched.
How the items are ordered
The maximum records to retrieve
Search for records based on the passed in search object. If the value is null or the default value, then the item will not be part of the where clause.
Syntax
Public Overloads Function Search(Of T As {Class, New})( _
   ByVal searchParameters As T, _
   ByVal orderBy As String, _
   ByVal maxRecords As Integer _
) As List(Of T)
Dim instance As DataHelper
Dim searchParameters As T
Dim orderBy As String
Dim maxRecords As Integer
Dim value As List(Of T)
 
value = instance.Search(Of T)(searchParameters, orderBy, maxRecords)
public List<T> Search<T>( 
   T searchParameters,
   string orderBy,
   int maxRecords
)
where T: class, new()
public: List<T*>* Search<T>( 
   T* searchParameters,
   string* orderBy,
   int maxRecords
) 
where T: ref class, gcnew()
public:
List<T^>^ Searchgeneric<typename T>
( 
   T^ searchParameters,
   String^ orderBy,
   int maxRecords
) 
where T: ref class, gcnew()

Parameters

searchParameters
What to search for. Default values are not searched.
orderBy
How the items are ordered
maxRecords
The maximum records to retrieve

Type Parameters

T
Generic class type

Return Value

A list of objects
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);
 
//Search parameters
Person searchParm = new Person();
searchParm.FirstName = "John";
string orderBy = string.Empty;
 
//Search by the passed parameters
List<Person> personList = db.Search<Person>(searchParm, orderBy);
 
//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()
 
'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)
 
'Search parameters
Dim searchParm As New Person()
searchParm.FirstName = "John"
Dim orderBy As String = String.Empty
 
'Search by the passed parameters
Dim personList As List(Of Person) = db.Search(Of Person)(searchParm, orderBy)
 
'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
Overload List