QueryParameter Class
A parameter passed to a SqlQuery.
Namespace: DevExpress.DataAccess.Sql
Assembly: DevExpress.DataAccess.v24.1.dll
NuGet Packages: DevExpress.DataAccess, DevExpress.Win.PivotGrid, DevExpress.Win.TreeMap
Declaration
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 retrieves data from the Microsoft SQL Server database and filters the resulting data set with a specified parameter value.
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.DataAccess.Sql;
// ...
SqlDataSource DataSource { get; set; }
// ...
void SqlDataSourceInitialization()
{
MsSqlConnectionParameters connectionParameters = new MsSqlConnectionParameters(){
ServerName = "localhost",
DatabaseName = "NorthWind",
UserName = null,
Password = null,
AuthorizationType = MsSqlAuthorizationType.Windows
};
DataSource = new SqlDataSource(connectionParameters);
}
// ...
void SelectQueryCreation()
{
SelectQuery query = SelectQueryFluentBuilder
.AddTable("Categories")
.SelectColumn("CategoryName")
.GroupBy("CategoryName")
.Join("Products", "CategoryID")
.SelectColumn("ProductName", AggregationType.Count, "ProductCount")
.SortBy("ProductName", AggregationType.Count,
System.ComponentModel.ListSortDirection.Descending)
.GroupFilter("[ProductCount] > 7")
.Build("Categories");
DataSource.Queries.Add(query);
QueryParameterInitialization(query);
}
// ...
void QueryParameterInitialization(SelectQuery query)
{
QueryParameter parameter = new QueryParameter()
{
Name = "catID",
Type = typeof(DevExpress.DataAccess.Expression),
Value = new DevExpress.DataAccess.Expression("?catID", typeof(System.Int32))
};
query.Parameters.Add(parameter);
query.FilterString = "CategoryID = ?catID";
}
You can use expressions to specify the query parameter value. Set the parameter’s Type property to the DevExpress.DataAccess.Expression type and assign an Expression instance to the parameter’s Value property. For more information on operators, functions, and constants, refer to the following help topic: Expression Language. In DevExpress reports, expressions can include report parameters. Prepend a report parameter’s name with the ? character in an expression to bind a query parameter to a report parameter.
Review the following examples on how to use the Expression to link query parameters with the report or dashboard parameters:
- Reporting - Filter Data at the Data Source Level (Runtime Sample)
- BI Dashboard - Pass a Dashboard Parameter Value to a Custom SQL Query