0

SSRS 执行服务 ParameterValue 变量索引失败

我正在尝试使用 SSRS 执行服务 ParameterValue 数组而不定义索引数。微软的例子是这样的: http://technet.microsoft.com/en-us/library/reportexecution2005.reportexecutionservice.render.aspx '准备报告参数。暗淡参数(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"

但我想添加可变数量的对象。我想做这样的事情:'准备报告参数。调暗参数()作为 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

显然我无法定义数组中索引的数量,因为我不知道 MyList 的 long 是谁。当我删除索引数量时,我收到此错误:“NullReferenceException 未被用户代码处理。对象引用未设置为对象的实例。” 有人对 SSRS ParameterValue 对象有经验吗?或者我的阵列建设做错了什么?希望我得到一个适用于 ParameterValue 的答案。

任何帮助表示赞赏,谢谢!

4

2 回答 2

1

你得到一个空引用,因为你的数组还没有被实例化。您必须设置数组的大小。

如果在声明数组时可以访问 MyList 对象,则可以执行以下操作来创建一个列表大小加三的数组。

' Gives size of three + list count
Dim parameters(MyList.Count + 2) As ParameterValue 

如果您只能在稍后阶段访问列表,则可以使用调整大小功能

Array.Resize(parameters, parameters.Length + MyList.Count)
于 2013-10-28T20:22:11.380 回答
0

此函数创建 SsrsExecutionService.ParameterValue 值的参数列表。然后它将 ParameterValue() 类型的参数名称和值添加到列表中。最后,它执行 List.ToArray 将 ParameterValue 列表放入 SSRS 接受的 ParameterValue 数组中。

这样做的目的是避免创建 ParameterValue 数组并且必须定义数组中索引的大小。您稍后将将此参数数组传递给报告服务执行服务: rs.SetExecutionParameters(parameters, "en-us")

这也是如何将 MDX 参数发送到 SSRS 的示例。

    Public Function ToMDXParamArray(startDate As String, endDate As String, employeeNames As String, gender As String, ethnicity As String) As SsrsExecutionService.ParameterValue()

        ' The function was passed a comma delited text string of employee names. They need to be split up and added to the parameter array indivudually.
        ' If this were a SQL query the whole string could be passed to a single parameter.
        Dim employeeList() As String = employeeNames.Split(",")


        ' Create a parameter list to hold SsrsExecutionService.ParameterValue values
        Dim paramList As New List(Of SsrsExecutionService.ParameterValue)
        ' Define a single ParameterValue. In SSRS this has Name, Value, and Label fields. 
        Dim p As New SsrsExecutionService.ParameterValue()

        ' Create a new ParameterValue
        p = New SsrsExecutionService.ParameterValue()
        ' Assigne a name and value
        p.Name = "StartDate"
        p.Value = "[EmploymentDates].[YearMonthDate].[Month].&[" + startDate + "]"
        ' Add that ParameterValue to the parameter list
        paramList.Add(p)

        p = New SsrsExecutionService.ParameterValue()
        p.Name = "EndDate"
        p.Value = "[EmploymentDates].[YearMonthDate].[Month].&[" + endDate + "]"
        paramList.Add(p)

        p = New SsrsExecutionService.ParameterValue()
        p.Name = "Gender"
        p.Value = "[" + gender + "]"
        paramList.Add(p)

        p = New SsrsExecutionService.ParameterValue()
        p.Name = "Ethnicity"
        p.Value = ethnicity
        paramList.Add(p)

        ' Now add that list of employee names. For Analysis Services/MDX the names have to be added individually. For SQL you pass the entire string to a single parameter.
        ' This loop of an unknown number of employees in employeeList is exactly why you don't want to create a parametersRdl(50) As SsrsExecutionService.ParameterValue with a defined index size.
        For x As Integer = 0 To employeeList.Count - 1
            p = New SsrsExecutionService.ParameterValue()
            p.Name = "ProvidersProviderLocation"
            p.Value = "[Employees].[Employee Store].[Employees].&[" + employeeList(x) + "]"
            paramList.Add(p)
        Next

        ' Create the Execution Service Parameter Value object
        Dim parametersRdl() As SsrsExecutionService.ParameterValue
        ' Assigne the parameter list to the SSRS ParameterValue array
        parametersRdl = paramList.ToArray()

        ' Return the ParameterValue
        Return parametersRdl
    End Function

在弄清楚这一点之前,我不得不再次用头撞墙,我希望这对其他人有所帮助。

于 2013-10-28T23:00:33.480 回答