Bean Software Search Control Documentation   
 
 
     




getWhereClause Method


Description:
Return WHERE clause of SQL Query to the database.

[Visual Basic .NET]

Public Function getWhereClause() As String

Public Function getWhereClause(ByVal SearchExpression As String) As String


[C#]

public String getWhereClause();

public String getWhereClause(String SearchExpression);


SearchExpression
   Depending of TypeOfSearch Property value, represents: searching terms, phrases or boolean expression with AND, OR and NOT keywords, brackets, quotes, wild characters etc.
If using getWhereClause without a SearchExpression parameter, then value of Text property is used as a SearchExpression.

Method returns a valid WHERE clause, that can be used in SQL query to return wanted rows from database. If SearchExpression parameter is an empty string or contains only NoiseWords, method can not build a valid WHERE clause. Also, that could happen if SearchColumns property does not contains any column to search. If getWhereClause can not return a valid WHERE clause, then its return value will depend on value of IfError property and return empty string, " 2 = 1 " string or throw exception.

Use this method to build your SQL Query and return wanted data from database. Before calling getWhereClause, you need to set all others properties if needed. You can do it in design time, or in run time if you like to give your users a possibility to change some search conditions.

[VB.NET]

' This is our SQL query
Dim SQLQuery As String = "SELECT * FROM MyQuery"

' First, it is needed to set parameters
SearchControl1.IfError = enuIfError.EmptyString
SearchControl1.TypeOfSearch = enuTypeOfSearch.AllWords
SearchControl1.SQLSyntax = enuSQLSyntax.MSSQLFullTextSearch

' Second, call the getWhereClause method
Dim WhereClause As String = SearchControl1.getWhereClause();

' If there is something to search, append this WHERE clause to your
' SQL query (e. g. user could write nothing to text box and just press
' Search button, so in that case there is no need to filter data rows)

If WhereClause <> "" Then

' Now you have a valid SQL that you could use to return data and
' display it to user

  SQLQuery &= " WHERE " & WhereClause
End If

[C#]

// This is our SQL query
String SQLQuery = "SELECT * FROM MyQuery";

// First, it is needed to set parameters, if their values are wrong
SearchControl1.IfError = enuIfError.EmptyString;
SearchControl1.TypeOfSearch = enuTypeOfSearch.AllWords;
SearchControl1.SQLSyntax = enuSQLSyntax.MSSQLFullTextSearch;

// Second, call the getWhereClause method
Dim WhereClause As String = SearchControl1.getWhereClause();

/* If there is something to search, append this WHERE clause to your
SQL query (e. g. user could write nothing to text box and just press
Search button, so in that case there is no need to filter data rows)
*/
if (WhereClause != "")
{

// Now you have a valid SQL query that you could use to return data
// and display it to user
  SQLQuery += " WHERE " + WhereClause;
}