views:

1169

answers:

3

I would like to be able to loop through all of the defined parameters on my reports and build a display string of the parameter name and value. I'd then display the results on the report so the user knows which parameters were used for that specific execution. The only problem is that I cannot loop through the Parameters collection. There doesn't seem to be an indexer on the Parameters collection, nor does it seem to implement IEnumerable. Has anyone been able to accomplish this? I'm using SSRS 2005 and it must be implemented within the Report Code (i.e., no external assembly). Thanks!

A: 

Unfortunately, it looks like there's no simple way to do this. See http://www.jameskovacs.com/blog/DiggingDeepIntoReportingServices.aspx for more info. If you look at the comments of that post, there are some ways to get around this, but they're not very elegant. The simplest solution will require you to have a list of the report parameters somewhere in your Report Code, which obviously violates the DRY principle, but if you want the simplest solution, you might just have to live with that.

You might want to rethink your constraint of no external assembly, as it looks to me that it would be much easier to do this with an external assembly. Or if your report isn't going to change much, you can create the list of parameter names and values manually.

Liron Yahdav
I didn't realise he meant from within the report while it's rendering. I will use reflection to poke around inside Microsoft.ReportingServices.ReportProcessing.ReportObjectModel.Parameters to see whether it can be cast to something more accessible.
Peter Wone
A: 

If I'm understanding your question, just do what I do: Drop a textbox on the report, then while you are setting up the report, insert the following: ="Parameter1: " + Parameters!Parameter.Label + ", Parameter2: " + Parameters!Parameter2.Label...

Granted, it's not the prettiest thing, but it does work pretty well in our app.

And I'm using Labels instead of Values since we have datetime values, and the user only cares about either the short date or the month and year (depending on circumstance), and I've already done that formatting work in setting up the parameters.

Pulsehead
A: 

I can think of at least two ways to do this. The first might work, the second will definitely work.

  1. Use the web service. I'm pretty sure I saw API for getting a collection of parameters. Even if there's no direct access you can always create a standard collection and copy the ReportParameter objects from one to the other in a foreach loop - and then access Count, with individual parameter properties available by dereferencing the ReportParameter instances.

  2. Reports are RDL. RDL is XML. Create an XmlDocument and load the RDL file, then use the DOM to do, well, anything you like up to and including setting default values or even rewriting connection strings.

If your app won't have file-system access to the RDL files you can get them via the web service.

Peter Wone