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

13 comments:

Nahid said...

Good Job Emad!
Thanks a million

Anonymous said...

Hi Emad, thanks for the tutorials on Reporting Services, they've been of great help. However, I have an error with passing the parameters from .NET. More precisely with "ReportParameter".

Shouldn't it be a class too, like ReportCredentials? I'm trying to figure it out to make it but I don't see how...

Any help will be welcomed, thank you in advance.

Emad Yazdan said...

hi Juan,
The ReportParameter class is the .net class please add the relevant namespace

Anonymous said...

Hi Emad, I've got it working. Thanks a lot for your help!
Juan

Gopalakrishnan said...

thank u its working gud,am also having one doubt, for example studentreport(.rdl) file which can stored in reportmanager, can we able to retrive the specific datas from the report and view it in the reportviewer, that means in that report lots of fields are available i want only to retrive the stuname and major field, it is posible? i want to retrive it from asp.net application and view that in the reportviewer

Thana said...

Hi

How to pass the other data types through parameter like int,bool....

Help us........


thana

Emad Yazdan said...

Hi Thana,

Why don't you pass integaer by using ToString Method and for bool you can pass "0" or "1"

Cheers,
Emad

Majid said...

Hi Emad;
Thanks for your awesome tutoring. How can I see you previous post regarding create report in reporting services. Do you add the parameter report at time of creating it. How can I get the whole code behind.

Thanks

Majid

Emad Yazdan said...

Hi Majid,

you can see the clip and int the reporting services section there are some other links

Anonymous said...

Thanks man,
this info helped me a lot.

Rachat de credit said...

Thank you it is a great support, now to pass parameters to reporting services from .net applications is definitely simple with the help of your tips. Kudos

vanne said...

thanks for this great stuff :D

Unknown said...

This is just the information I am finding everywhere. Thanks you, I just subscribe your blog.


Yen
www.gofastek.com