本文介绍了SSRS 执行服务 ParameterValue 变量索引失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

SSRS Execution Service ParameterValue variable index failing

我正在尝试使用 SSRS 执行服务 ParameterValue 数组,但未定义索引数量.微软的例子是这样的:http://technet.microsoft.com/en-us/library/reportexecution2005.reportexecutionservice.render.aspx' 准备报告参数.Dim parameters(2) As ParameterValue

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"

但我想添加可变数量的对象.我想做这样的事情:' 准备报告参数.Dim parameters() As ParameterValue

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

显然我无法定义数组中索引的数量,因为我不知道MyList是谁.当我删除索引数量时,出现此错误:用户代码未处理 NullReferenceException.对象引用未设置为对象的实例."有没有人有使用 SSRS ParameterValue 对象的经验?还是我的阵列构建有问题?希望我得到一个适用于 ParameterValue 的答案.

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.

感谢任何帮助,谢谢!

推荐答案

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

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.

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

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")

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

This is also an example of how to send MDX parameters to 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

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

Once again I had to beat my head against a wall before figuring this out, I hope this helps others.

这篇关于SSRS 执行服务 ParameterValue 变量索引失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 22:22