Do not use the CSearch class directly. Use the preallocated WIDatabase.Search variable instead.
Namespace: Wiker.WIDatabaseFunctions to Search (SELECT) data records from a database.
Following steps are required for proper operation:
- Clear - Clear previous search criteria and results. Not required if first time used.
- Column - Select tables and columns with optional aliases of data to be retrieved
- Table - Set main table to retrieve data from
- Condition - Define conditions (WHERE) of search
- Execute - Execute the search upon the database
- Read - Read a single record or loop though all results
- Get - Get data from record just retrieved from Read() and store in selected variables
Optional operations:
- Join - Retrieve data from more than one table
- Count - Return number of records in table
- Distinct - Return number of different/distinct records in table
- DistinctCount - Number of different/distinct records in table
- Sort - Select how to sort search results
- Limit - Specify how many results to return
Assembly:
Syntax
C# |
---|
public class CSearch : CConditionCommon |
Visual Basic |
---|
Public Class CSearch _ Inherits CConditionCommon |
Visual C++ |
---|
public ref class CSearch : public CConditionCommon |
Examples

WIDatabase WIDB; CDatabaseInfo DBInfo; /* Create CDatabaseInfo object and populate with database login info */ DBInfo = new CDatabaseInfo(); DBInfo.DatabaseType = eDatabaseType.SQL; DBInfo.Location = "SqlServer"; DBInfo.DBName = "TestDatabase"; DBInfo.Username = "LoginName"; DBInfo.Password = "LoginPassword"; /* Create new instance of WIDatabase */ WIDB = new WIDatabase(DBInfo); /* Select columns to retrieve */ WIDB.Search.Column("FirstName"); WIDB.Search.Column("LastName"); WIDB.Search.Column("Dogs"); WIDB.Search.Column("Cats"); /* Retrieve results where column 'Dogs' does not equal 0 OR 'Cats' does not equal 0 */ WIDB.Search.Condition("Dogs", eOperator.NotEqual, 0); WIDB.Search.Condition(eLogic.OR) WIDB.Search.Condition("Cats", eOperator.NotEqual, 0); /* Order results by 'LastName' then 'FirstName' */ WIDB.Search.Sort("LastName", eSort.Ascending); WIDB.Search.Sort("FirstName", eSort.Ascending); /* Only return 100 records */ WIDB.Search.Limit(100); /* Execute search on database */ if (!WIDB.Search.Execute()) { MessageBox.Show(string.Format("Failed To Search Table\n{0} - {1}", WIDB.LastError.ToString(), WIDB.LastErrorMessage)); return(false); } /* Loop though results */ while (WIDB.Search.Read()) { /* Note: Get()'s do not need to be in the same order as Column()'s */ WIDB.Search.Get("Dogs", out DogCount); WIDB.Search.Get("Cats", out CatCount); WIDB.Search.Get("LastName", out LastName); WIDB.Search.Get("FirstName", out FirstName); } WIDB.Close();