Multi-value SSRS report parameters from C#

If you are calling SSRS reports from C# and setting the parameters programatically you will sooner or later come across a case where you have to assign a parameter with multiple values. This problem proved quite vexing but I have found the (rather simple) solution so here it is:

string[] foobarValues = new string[] { "foo", "bar", "rnd" };

//Create the list of parameters that will be passed to the report
List reportParameters = new List();

//Set up the multi-value parameter and add the foobarValues array to it
ReportParameter multiValueParam = new ReportParameter("foobar");
multiValueParam.Values.AddRange(foobarValues);

//Finally we add the multi-value parameter to our main parameter list
reportParameters.Add(multiValueParam);

//Set the ReportViewers parameters to the list of ReportParameters we just created
reportViewer.ServerReport.SetParameters(reportParameters.ToArray());

And that is it. Plain and simple. :)

 
117
Kudos
 
117
Kudos

Now read this

Darksiders

Remember when I said that I might post fun little rants? No…? Well, here is my first one. So yesterday I decided that I needed to play some games and ended up choosing Darksiders, a hack and slash set on post apocalyptic earth. Should be... Continue →