(How)
C^# You Are - 25 February 2007
SQL Server Reporting Services and the ReportViewer control.
- What is the difference between a local report and a server report in the
ReportViewer control? Answer
A local report is an RDL report that is generated locally from a data set.
A server report is an RDL report that is maintained and generated through SQL Server
Reporting Services.
- What database(s) are supported by a local report? A server report? Answer
Local reports, since they are generated by a data set, support any database (or
even no database). A server report is generated through SQL Server Reporting
Services so it requires SQL Server.
- How can you prompt a user for report parameters? Answer
By default ReportViewer will display the parameters above the report
so a user can specify the parameter values. This is controlled through the
ShowParameterPrompts property.
- How do you control what parameters are displayed to the user? Answer
Each parameter in the report definition specifies whether it is shown or not via
the Hidden property which is normally set when the parameter is
defined.
- How do you programmatic set a parameter value? Answer
This is a little trickier. If you know the exact parameter you want to set
then you can create an instance of the ReportParameter class, set
the name and the value and then call SetParameters on the report.
ReportParameter parm1 = new ReportParameter("Parameter 1", "Hello World");
ReportViewer1.ServerReport.SetParameters(new ReportParameter { parm1 });
However if you need to programmatically retrieve and set parameters based upon the
definition then you must first retrieve the parameter information and then create
a new parameter based off the original. The parameter information is a different
type than the parameter value so they can't be reused.
ReportParameterInfoCollection parms = ReportViewer1.ServerReport.GetParameters();
foreach(ReportParameterInfo parm in parms)
{
ReportParameter newParm = new ReportParameter(parm.Name, "Some value");
...
}