Skip to main content
A newer version of this page is available. .

QueryParameter Class

A parameter passed to a SqlQuery.

Namespace: DevExpress.DataAccess.Sql

Assembly: DevExpress.DataAccess.v18.1.dll

Declaration

public sealed class QueryParameter :
    DataSourceParameterBase

Remarks

A collection of QueryParameter objects is returned by the SqlQuery.Parameters property. This property is also available for the StoredProcQuery class.

The following code illustrates how to bind to a Microsoft SQL Server database and filter the result set of a query by a specified parameter value.


using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Sql;
// ...

private SqlDataSource BindToData(int parameterValue) {
    // Specify parameters required to connect to a specific data provider.
    MsSqlConnectionParameters connectionParameters =
        new MsSqlConnectionParameters("ServerName", "DataBaseName", null, null, MsSqlAuthorizationType.Windows);

    // Create a data source instance with the specified connection parameters.
    SqlDataSource ds = new SqlDataSource(connectionParameters);

    // Create a query to access fields of the Products data table.
    // End the chain by calling the Build method with a specified query name.
    SelectQuery query = SelectQueryFluentBuilder
        .AddTable("Products")
        .SelectColumns("CategoryID", "ProductName")
        .Build("Products");

    // Create a query parameter of a required type and assign a value to it.
    QueryParameter parameter = new QueryParameter() {
        Name = "catID",
        Type = typeof(System.Int32),
        Value = parameterValue
    };
    query.Parameters.Add(parameter);

    // Filter the query result set using the created parameter.
    query.FilterString = "CategoryID = ?catID";

    // Add the query and fill the data source.
    ds.Queries.Add(query);
    ds.Fill();

    return ds;
}

To learn how to link query parameters with report or dashboard parameters using an Expression, refer to the following tutorials.

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

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.

Implements

Inheritance

See Also