In our previous post (https://gilbertadjin.wordpress.com/2010/07/05/reporting-with-reporting-services/) we went through how to create reports with reporting services. In instances where you want to insert some records onto the reports which are not part of the data source, for example, inserting dates into your report title, you need to create parameters. It is assumed you can create reports with reporting services.
In this post we will be adding two parameters “name” and “title” to our reports. After creating the report, in the report data pane (if not shown, go to the menu bar, click on “View” then “Report Data” to show the pane
Below is the look of the report data pane
In the Report Data pane, right click on the “parameters” node and click on add parameter. A dialog box shown below is presented. Enter the name of your parameter and choose the data type.
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)