IDataStore.SetFilter(string format) Method
.NET Standard 2.x
Specifies the filter criteria for the DataStore.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public bool SetFilter(string format);
Parameters
format
System.String
A string whose value is a Boolean
expression that you want to use as the filter criteria. The expression includes column names or numbers. A column number must be preceded by a pound sign (#).
Returns
System.Boolean
Returns true
if it succeeds and false
if the format
is not correct.
Remarks
A DataWindow object
can have filter criteria specified as part of its definition. After data is retrieved, rows that do not meet the criteria are immediately transferred from the primary buffer to the filter buffer.
The SetFilter
method replaces the existing filter criteria -- if any are defined for the DataWindow object
-- with a new set of criteria. Call the Filter
method to apply the filter criteria and transfer rows that do not meet the filter criteria to the filter buffer.
The filter expression consists of columns, relational operators, and values against which column values are compared. Boolean expressions can be connected with logical operators AND
and OR
. You can also use NOT
, the negation operator. Use parentheses to control the order of evaluation.
Examples
The following code example defines the filter expression that only records whose budget is equivalent to or larger than 200000 are displayed.
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.IDataStoreExamples
{
public class SetFilterExample
{
private readonly SchoolContext _context;
public SetFilterExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example()
{
// Instantiates a DataStore object with datawindow: d_department.
var datastore = new DataStore("d_department", _context);
datastore.Retrieve();
Console.WriteLine("Before Filter, Rowcount: {0}",
datastore.RowCount);
// Calls SetFilter to define a filter: Budget >= 200000.
// Calls Filter to apply the filter.
datastore.SetFilter("Budget >= 200000");
datastore.Filter();
Console.WriteLine("After Filter, Primary Buffer Rowcount: {0}",
datastore.RowCount);
Console.WriteLine("After Filter, Filter Buffer Rowcount: {0}",
datastore.FilteredCount);
/*This code produces the following output:
Before Filter, Rowcount: 4
After Filter, Primary Buffer Rowcount: 3
After Filter, Filter Buffer Rowcount: 1
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x