How to Create Parameterized Reports With Reporting Services

In this post, I will show you how to add two parameters “name” and “title” to our reports. If you are new in Reporting Services, you can check this tutorial. It's very simple to understood. Now, after you have created the report, in the report data pane, click on the “View” then “Report Data” to show the pane.

image_1.png

This below image shown the report data pane

image_2.png

In the Report Data Pane, right click on the “parameters” node and click on add parameter. A dialog shown below is presented. Enter the name of your parameter and choose the data type.

image_3.png

On the design you are done. Go to you where the report data will be supplied in your code. Make sure to import (“Imports Microsoft.Reporting.WinForms“).

For example we have a procedure which accepts parameters including a collection of parameters

   1: Public Sub fillReport(ByVal dataset As String, ByVal reportname As String, ByVal loadData As DataTable, ByVal parameters As ReportParameterCollection)
   2:        Me.ReportViewer1.ProcessingMode = ProcessingMode.Local
   3:        Me.ReportViewer1.LocalReport.ReportPath = Application.StartupPath + "/" + reportname + ".rdlc"
   4:        Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource(dataset, loadData))
   5:        Me.ReportViewer1.LocalReport.SetParameters(parameters)
   6:        Me.ReportViewer1.RefreshReport()
   7:    End Sub

We then give values to our parameters then we call our method above which will complete the job

   1: title = " Report on Sales made between " & Me.dtpStart.Value.ToShortDateString & " and " & Me.dtpEnd.Value.ToShortDateString
   2: Dim name As String = " Just trying"
   3: Dim parameters As New ReportParameterCollection()
   4: parameters.Add(New ReportParameter("title", title))
   5: parameters.Add(New ReportParameter("name", name))
   6: fillReport("DataSet1", "salesReports", Me.FarmershopeDataSet.SalesReports, parameters)

Hope you enjoy this tutorial. J

Ebook Download
View all
Learn
View all