Thursday, June 5, 2008

How to pass parameters to Reporting Services from .Net applications

In the previous post you saw how to create a report in reporting services and you also learned how to create parameter for the report. You simple can show the same report and you do not need to pass parameter since everything is inside the report. But unfortunately you cannot change the UI of State dropdownlist or View Report button. So you may want to remove this parameter palette and show this information in another custom control then pass the information to reporting service.

First add a dropdownlist to the page that has the states and also a report viewer control and a button to trigger to show the report.

Add all states on the dropdownlist either by loading information from database or adding them manually. Then on button click please write this code

ReportViewer1.ShowCredentialPrompts = false;

ReportViewer1.ServerReport.ReportServerCredentials = new ReportCredentials("emady", "MyPassword", "hhi");

ReportViewer1.ServerReport.ReportServerUrl = new Uri("http://falcon/Reportserver");

ReportViewer1.ServerReport.ReportPath = "/Report Project State/Report1";

List<ReportParameter> parameters = new List<ReportParameter>();

parameters.Add(new ReportParameter("state", DropDownListStates.SelectedItem.Text));

ReportViewer1.ServerReport.SetParameters(parameters);

ReportViewer1.ProcessingMode = ProcessingMode.Remote;

ReportViewer1.ShowParameterPrompts = false;

ReportViewer1.ShowPromptAreaButton = false;

ReportViewer1.ServerReport.Refresh();

The only change that you may see compare to what we had in previous clip is that:

We set that we do not want seeing any credentials error prompt. Moreover, we create a list of ReportParameter and add the state parameter to this list and we are passing this list to SetParameter method. Also we are hiding parameter part from report. Finally we are hiding any prompt from report server.

Important: ReportCredentials class is a custom class please get the code from previous posts about reporting services. Also please see the clip to understand how it works.

please see the clip

Tuesday, June 3, 2008

How to create a parameterized report with Reporting Services

please see the clip

I assuming you have already read the previous posts about Reporting Services and you familiar with creating report. Let's say you have the same project in previous post. And you need to show just post code information that is in just one specific State. I am going to explain how to create a state parameter.

Open the report then go to Data View and select"New DataSet..."

Then all you need write a query to show all the states like this:

Then Select the previous data source and change the query as below. Remember when your query has some parameters (in reporting service @variable is a parameter) it will be automatically added to Report Parameters

So this query will need a state to run. From Report menu select Report Parameters you need to select "From query" radio button from "Available values" and also set the default value. As below (for more information see the clip)

The result should be like this:


please see the clip