How to Add Parameters to Your C# .NET Report Application
Tags: webdev, devops, csharp, tutorial
Published: 2023-08-22 18:25:53

---
canonical_url: https://developer.mescius.com/blogs/how-to-add-parameters-to-your-c-sharp-net-application
description: Learn how to add parameters to your C# .NET reporting application. See more from ActiveReports today.
---
In ActiveReports.NET, parameters enable you and/or your end users to control report data, connect related reports together, and vary report presentation. Report parameters can be used to solve tasks such as filtering, conditional formatting, data binding, creating dynamic report layouts, and much more.

This blog is accompanied by a video. Both the video and the blog will go through the same steps to achieve the same results. If you'd like to follow the video instead or use both together:

{% embed https://youtu.be/nc_qEZtJqwM %}

In this guide, we’ll show how easy it is to work with parameters in [ActiveReports](https://developer.mescius.com/activereports). We’ll continue using the report that we generated in our [Getting Started - How to Create a .NET Report guide](https://developer.mescius.com/blogs/how-to-generate-net-banded-report-in-your-desktop-application).

As a reminder, this is an inventory report using a table that is grouped by product categories. It shows each product’s name, color, price, and size.

![C# Report Parameters](https://files.grapecity.com/gc-website-media/onwl2ykq/01-parameters.png?width=473.4927234927235&height=500)

We want to filter this report based on color. Therefore, we'll need to create a parameter to indicate that the user needs to select a color, pass that selection to the report, and filter the data based on that parameter.

## Section 1: Add a dataset for the parameter values

First, we'll create another dataset specifically for the parameter values.

1\. Right-click the MyDS data source node and select “Add Data Set.”

2\. Set the name to “ParamDataSet”

3\. On the Query tab, I want to query a list of distinct colors from my Products table

```
    select DISTINCT color
    from SalesLT.Product
    where SalesLT.Product.Color is not null
```
4\. Click OK to close the dialog box.

## Section 2: How to add a parameter

Now, we need to create a parameter input field in the report so the user is prompted to make a selection.

1\. Right-click the “parameters” node in the Report Explorer and select “Add Parameter.”

2\. On the resulting dialog box’s General tab, we’ll rename the parameter and enter a text that directs the user to make a selection.

*   Name: “ReportParam”
*   Text: “Select ‘color’ of your choice:”

![C# Report Parameters](https://files.grapecity.com/gc-website-media/0xpfgq5r/02-parameters.png?width=500&height=321.9971056439942)

3\. On the Available Values tab, we’ll select “From Query” since we created a Dataset for this parameter. We’ll select the Dataset we created earlier, “ParamDataSet” from the Dataset drop-down.

4\. The Value and Label fields will only have one choice since that’s the only field we have selected in our query.

*   Select “color” for both

![C# Report Parameters](https://files.grapecity.com/gc-website-media/3q5jchda/03-parameters.png?width=500&height=266.5544332210999)

5\. Click OK to close the dialog box.

## Section 3: Pass the parameter

Next, we need to edit the Products dataset and pass the parameter to the Products query.

1\. Right-click the “Products” data set and choose “Edit.”

2\. In the Products Data Set dialog box, go to the “Parameters” tab

3\. Add a Parameter

4\. Rename it to QueryParam

5\. Pass the value from the report parameter created in Section 2 using an expression

*   =Parameters!ReportParam_color.Value

![C# Report Parameters](https://files.grapecity.com/gc-website-media/sn3iogxn/04-parameters.png?width=500&height=230.12232415902142)

6\. On the Query tab, we’ll add the query parameter (which we just created) to the where clause and filter the query based on the value of the parameter selected. (Line 3 of the snippet below)

```
    select *
    from SalesLT.Product
    where (SalesLT.Product.Color=@QueryParam AND
    (SalesLT.Product.Thumbnailphotofilename not in (select
    SalesLT.Product.thumbnailphotofilename from SalesLT.Product where
    SalesLT.Product.thumbnailphotofilename = 'no_image_available_small.gif')))
```
Now you should be good to go! If we run the project, we should now have a dropdown box where the user can select a color.

![C# Report Parameters](https://files.grapecity.com/gc-website-media/kqwixrp4/05-parameters.png?width=218&height=246)

And the resulting report preview will be filtered only to show products of that color.

![C# Report Parameters](https://files.grapecity.com/gc-website-media/awwamzu3/06-parameters.png?width=500&height=386.1336032388664)

Additional tutorials are available on our [ActiveReports blog page](https://developer.mescius.com/blogs/categories/products/activereports).