How to set multiple integer ReportParameter in c#?
Asked Answered
I

1

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?

Illsuited answered 8/4, 2013 at 18:32 Comment(7)
Does that even compile?Lalise
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 msdn.microsoft.com/en-us/library/ms252178%28v=vs.80%29.aspxCindacindee
Looks like ReportParameter does not have a constructor that can take an int array. Try new ReportParameter("storeSelected", new[]{"2","3","4"}, false).Thimbleful
I have clarified my question.Illsuited
@YongkeBillYu you cannot initiate an int[] using string values. Try the line I gave you above.Thimbleful
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.Illsuited
@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"}).Thimbleful
L
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)
);
Lalise answered 8/4, 2013 at 18:36 Comment(9)
+1 Looks good to me.. as well as what the documentation statesCindacindee
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.Illsuited
@YongkeBillYu, the code you had before couldn't have possibly compiled unless you're using a different library.Lalise
Yes, you are right, it does not compile, how do I make it compile?Illsuited
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.Lalise
I am simply tring to pass an array of integers to the SetParameter function, there must be a way to achieve this.Illsuited
@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.Lalise
OK! I followed your suggestion and was able to do it, but it was through ALOT of hoops.Illsuited
Yeah, the .NET API is weak for SSRS integration. One reason for that is because the web service exposed by SSRS is weak.Lalise

© 2022 - 2024 — McMap. All rights reserved.