7

I am using Report Builder and loading the report in c#, also setting some parameters in c# too:

My question is, how do I set a ReportParameter of multiple integer values when I have it stored in an array?

I have tried the following:

 MyReportViewer.ServerReport.SetParameters(
      new ReportParameter("storeSelected", new int[3]{2,3,4}, false)
 );

However, this does not work, because ReportParameter does not take int.

I have also tried the following:

 MyReportViewer.ServerReport.SetParameters(
      new ReportParameter("storeSelected", new int[3]{"2", "3", "4" }, false)
 );

This also does not work as my parameter "storeSelected" is of type int, and will throw a type conversion error.

What do I need to do to pass my array of integer into the reportParameter?

Bill Software Engineer
  • 7,362
  • 23
  • 91
  • 174
  • Does that even compile? – Mike Perrenoud Apr 08 '13 at 18:35
  • What does `However this doesn't work` Mean..? what are you seeing vs what are you expecting. Take a look at this MSDN site it appears you are no passing the `ReportParams[]` properly http://msdn.microsoft.com/en-us/library/ms252178%28v=vs.80%29.aspx – MethodMan Apr 08 '13 at 18:35
  • Looks like ReportParameter does not have a [constructor](http://msdn.microsoft.com/en-us/library/microsoft.reporting.winforms.reportparameter.reportparameter(v=vs.100).aspx) that can take an int array. Try `new ReportParameter("storeSelected", new[]{"2","3","4"}, false)`. – Eren Ersönmez Apr 08 '13 at 18:38
  • I have clarified my question. – Bill Software Engineer Apr 08 '13 at 18:43
  • @YongkeBillYu you cannot initiate an int[] using string values. Try the line I gave you above. – Eren Ersönmez Apr 08 '13 at 18:46
  • I have and unfortunately it does not work because the parameter is of type integer and not string so it throw an type cast error. – Bill Software Engineer Apr 08 '13 at 18:47
  • @YongkeBillYu I think you are doing something wrong because I just tried my suggestion and it works just fine. Notice the difference between what you say you tried (`new int[]{"1","2","3"}`) and what I'm suggesting (`new[]{"1","2","3"}`). – Eren Ersönmez Apr 08 '13 at 18:59

1 Answers1

6

Based on the documentation by Microsoft, this line of code should read:

MyReportViewer.ServerReport.SetParameters(
    new ReportParameter("storeSelected", new string[] { "2", "3", "4" }, false)
);
Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232
  • `+1` Looks good to me.. as well as what the documentation states – MethodMan Apr 08 '13 at 18:39
  • Unfortunately it does not work because storeSelected is of type int that can take multiple values. Threw a "Cannot implicitly convert type 'string' to 'int'" error. – Bill Software Engineer Apr 08 '13 at 18:40
  • @YongkeBillYu, the code you had before couldn't have possibly compiled unless you're using a different library. – Mike Perrenoud Apr 08 '13 at 18:41
  • Yes, you are right, it does not compile, how do I make it compile? – Bill Software Engineer Apr 08 '13 at 18:42
  • You can't make it compile, there is no constructor with that signature. The problem is **almost certainly** now in the stored procedure or view that is leveraging the parameter and not in the line of code. In short, now you are going to have to work on your report. – Mike Perrenoud Apr 08 '13 at 18:44
  • I am simply tring to pass an array of integers to the SetParameter function, there must be a way to achieve this. – Bill Software Engineer Apr 08 '13 at 18:46
  • @YongkeBillYu, I'm sorry, but there literally is no signature for it. In fact, I've found a couple articles already that state it's not supported with the .NET API, so you're going to need to change your parameter to be a `string[]` instead. – Mike Perrenoud Apr 08 '13 at 18:50
  • 1
    OK! I followed your suggestion and was able to do it, but it was through ALOT of hoops. – Bill Software Engineer Apr 08 '13 at 19:45
  • Yeah, the .NET API is weak for SSRS integration. One reason for that is because the web service exposed by SSRS is weak. – Mike Perrenoud Apr 08 '13 at 19:50