Showing posts with label displayed. Show all posts
Showing posts with label displayed. Show all posts

Saturday, February 25, 2012

Parameters and ReportViewer

I have a report in which I am trying to get a parameter to be displayed in a textbox. I have declared a parameter in my .rdlc called UserName and the expression in the textbox is as follows...

=Parameters!UserName.Value

With that said, I have code in the window containing my ReportViewer to set the parameters and run my report as shown below...

string UserName = "test";

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

paramList.Add(new ReportParameter(UserName));

this.baseReportViewer.LocalReport.SetParameters(paramList);

this.baseReportViewer.RefreshReport();

With these things in mind, can anyone here provide me with a reason as to why my report on comes up with a message stating "An error occurred during local processing. One or more parameters required to run the report have not been specified." ?

If I remove the parameter and text box and strip out the code pertaining to the paramter in my window, the report runs without error.

Any ideas?

Answered my own question and it was a total noob mistake.

Assuming I have a parameter in my report named "UserName," the code in my form would need to look like the following...(I've highlighted the change in red)

string UserName = "test";

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

paramList.Add(new ReportParameter("UserName", UserName));

this.baseReportViewer.LocalReport.SetParameters(paramList);

this.baseReportViewer.RefreshReport();

Parameters

I am failry new to sql 2005 report services. I was wondering when using parameters to alter the information that is displayed in a report, can you use a request object to go against your query?
ie: Select * from table1 where ID = request("ID")
What I am doing is opening a report from a webpage and printing out what is displayed in a report. Some are straight forward that are just a listing of information where others the results are based on a unique value like an ID that is passed in the URL. Is there anyway to pass that to the report as well and filter the information based on a request or something along those lines?

Thanks in advance!

Hmm, I don't know if I understand you but when designing your report, create dataset with query: "select * from table1 where ID = @.ID" then in report parameters define @.ID parameter (it can be "static" or depend on another dataset).

Next, before you execute report you must assign to your parameter a value. In Rerpoting Services portal you have GUI that allow user to do so. You can also create GUI for your report parameters on your web page and send parameter values in URL.

Maciej