SSRS Execution Service ParameterValue variable index failing
I’m trying to use the SSRS Execution Service ParameterValue array without defining the number of indices. Microsoft’s example is this: http://technet.microsoft.com/en-us/library/reportexecution2005.reportexecutionservice.render.aspx ' Prepare report parameter. Dim parameters(2) As ParameterValue
parameters(0) = New ParameterValue()
parameters(0).Name = "EmpID"
parameters(0).Value = "288"
parameters(1) = New ParameterValue()
parameters(1).Name = "ReportMonth"
parameters(1).Value = "6" ' June
parameters(2) = New ParameterValue()
parameters(2).Name = "ReportYear"
parameters(2).Value = "2004"
But I want to add a variable number of objects. I want to do something like this: ' Prepare report parameter. Dim parameters() As ParameterValue
parameters(0) = New ParameterValue()
parameters(0).Name = "EmpID"
parameters(0).Value = "288"
parameters(1) = New ParameterValue()
parameters(1).Name = "ReportMonth"
parameters(1).Value = "6" ' June
parameters(2) = New ParameterValue()
parameters(2).Name = "ReportYear"
parameters(2).Value = "2004"
For x As Integer = 0 To MyList.Count - 1
' Start
Dim n As Integer = x + 3 ' Start adding values after the last entry
parametersRdl(n) = New ParameterValue()
parametersRdl(n).Name = "NameFromMyList"
parametersRdl(n).Value = MyList(x)
Next
Obviously I can’t define the number of indices in the array, because I don’t know who long MyList is. When I remove the number of indices I get this error: “NullReferenceException was unhandled by user code. Object reference is not set to an instance of an object.” Does anyone have experience with the SSRS ParameterValue object? OR am I doing something wrong with my array building? Hopefully I get an answer that works with ParameterValue.
Any help is appreciated, thanks!
This function creates a parameter list of SsrsExecutionService.ParameterValue values. It then adds parameter Names and Values of type ParameterValue() to the list. At the very end it does a List.ToArray to put the ParameterValue list into the ParameterValue array that SSRS accepts.
The purpose of this is to avoid creating a ParameterValue array and having to define the size of the index in the array. You will later pass this parameter array to reporting serives execution service: rs.SetExecutionParameters(parameters, "en-us")
This is also an example of how to send MDX parameters to SSRS.
Once again I had to beat my head against a wall before figuring this out, I hope this helps others.
You're getting a null reference because your array has not been instantiated. You have to set the size of the array.
If you have access to the MyList object when declaring the array, you can do the following to create an array the size of the list plus three.
If you only have access to the list at a later stage you can use the Resize function