Back to Devexpress

SelectQuery.FilterString Property

corelibraries-devexpress-dot-dataaccess-dot-sql-dot-selectquery.md

latest5.8 KB
Original Source

SelectQuery.FilterString Property

Specifies the criteria used to filter data returned by the current SelectQuery.

Namespace : DevExpress.DataAccess.Sql

Assembly : DevExpress.DataAccess.v25.2.dll

NuGet Package : DevExpress.DataAccess

Declaration

csharp
[DefaultValue(null)]
[LocalizableCategory(DataAccessStringId.QueryPropertyGridTableSelectionCategoryName)]
public string FilterString { get; set; }
vb
<DefaultValue(Nothing)>
<LocalizableCategory(DataAccessStringId.QueryPropertyGridTableSelectionCategoryName)>
Public Property FilterString As String

Property Value

TypeDefaultDescription
Stringnull

A String value, specifying the filter criteria.

|

Remarks

The FilterString property allows you to filter the result set returned by SelectQuery by specifying the required filter criteria. To filter a SelectQuery by specified column values, precede a column name with a corresponding table name. For instance, you can filter the SalesPerson table by the Beverages category in the following way.

csharp
SelectQuery query = new SelectQuery("Query 1");
query.AddTable("SalesPerson").SelectColumns("CategoryName", "Extended Price");
query.FilterString = "[SalesPerson].[CategoryName] = 'Beverages'";
vb
Dim query As New SelectQuery("Query 1")
query.AddTable("SalesPerson").SelectColumns("CategoryName", "Extended Price")
query.FilterString = "[SalesPerson].[CategoryName] = 'Beverages'"

To pass a QueryParameter (which can be accessed using the SqlQuery.Parameters property) to the filter string, precede the parameter name with the ? sign.

csharp
//...
QueryParameter queryParam1 = new QueryParameter("Parameter1", typeof(string), "Beverages");
query.Parameters.Add(queryParam1);
query.FilterString = "[SalesPerson].[CategoryName] = ?Parameter1";
vb
'...
Dim queryParam1 As New QueryParameter("Parameter1", GetType(String), "Beverages")
query.Parameters.Add(queryParam1)
query.FilterString = "[SalesPerson].[CategoryName] = ?Parameter1"

Note

If a table or column name includes dots, enclose the table/column name in square brackets.

For example, if you have a table with the “table.name” name and a column with the “column.name” name, refer to the column in the following manner: [[table.name].[column.name]]. If you have only the column name with a dot, refer to it as follows: [tablename.[column.name]]. As you can see, you should use \ to avoid closing the expression beforehand.

To learn more about building filter criteria, see Simplified Criteria Syntax.

The following code snippets (auto-collected from DevExpress Examples) contain references to the FilterString property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

reporting-winforms-filter-report-data-query/CS/QueryParametersRuntime/XtraReport1.cs#L39

csharp
query.Parameters.Add(parameter);
query.FilterString = "CategoryID = ?catID";

data-access-library-create-data-sources-at-runtime/CS/SqlDataSourceSnippets/Code.cs#L56

csharp
query.Parameters.Add(parameter);
    query.FilterString = "CategoryID = ?catID";
}

reporting-winforms-filter-report-data-query/VB/QueryParametersRuntime/XtraReport1.vb#L37

vb
query.Parameters.Add(parameter)
query.FilterString = "CategoryID = ?catID"

data-access-library-create-data-sources-at-runtime/VB/SqlDataSourceSnippets/Code.vb#L37

vb
query.Parameters.Add(parameter)
    query.FilterString = "CategoryID = ?catID"
End Sub

See Also

GroupFilterString

SelectQuery Class

SelectQuery Members

DevExpress.DataAccess.Sql Namespace