/winforms-dashboard-pass-dashboard-parameters-to-stored-procedure

This example shows how to pass a dashboard parameter to a stored procedure.

Primary LanguageC#OtherNOASSERTION

Dashboard for WinForms - How to Pass a Dashboard Parameter to a Stored Procedure

This example shows how to pass a dashboard parameter to a stored procedure. In this example, the DashboardDesigner.CustomParameters event is handled to change the dashboard parameter's default value before it is passed to the stored procedure.

In the result, only the values specified in the CustomParameters event are in effect.

Dashboard - Result

Example Overview

To pass a dashboard parameter to a stored procedure, do the following.

Create a Dashboard Parameter

To create a dashboard parameter, click the Parameters button from the Dashboard page group on the Ribbon's Home page. Click Add to create a dashboard parameter.

In this example, the orderIDs dashboard parameter is created. Specify the following settings:

  • Enable the Allow Multiselect property to select multiple values for the parameter.
  • Set the Look-up Settings property to Static List. The following values are available for the parameter: 10248, 10249, 10250.
  • Enable the Select All property to select all values in the initial state of the dashboard.

Dashboard Parameter Settings

Select a Stored Procedure

In the Query Editor dialog, select a stored procedure. In this example, the GetOrdersByID stored procedure from the NWind.mdf database is used.

Select A Stored Procedure

On the next page, bind the query parameter to the dashboard parameter created earlier.

Bind the Query Parameter to the Dashboard Parameter

You cannot pass a multi-value parameter value to a stored procedure directly. To pass a multi-value parameter to a stored procedure, convert the array of parameter values to a string with the JOIN() function if you use the Microsoft SQL Server, MySQL, or Oracle database system. The stored procedure code should parse the resulting string to get the dashboard parameter values.

To do this, on the second page of the Query Editor, enable the Expression check box for the query parameter. From the drop-down list in the Value column, select the Expression Editor option.

Query Parameters Settings

In the invoked Expression Editor, pass the name of the dashboard parameter (?OrderIDS) to the JOIN() function.

Expression Editor

Click OK to apply the specified settings.

Change the Default Parameter Value in Code

Handle the DashboardDesigner.CustomParameters event and specify the value to be passed to the stored procedure.

private void DashboardDesigner_CustomParameters(object sender, DevExpress.DashboardCommon.CustomParametersEventArgs e) {
	var customerIDsparam = e.Parameters.FirstOrDefault(p => p.Name == "orderIDs"); ;
	if (customerIDsparam != null) {
		customerIDsparam.Value = new string[] {"10251", "10252", "10253", "10254"} ;

	}
}

As a result, a user sees a dashboard based on the data from the stored procedure with the data query parameter's value specified in the DashboardDesigner.CustomParameters event handler (10251, 10252, 10253, 10254).

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)