如何按名称引用SSRS报告参数

时间:2015-02-12 22:47:59

标签: vb.net reporting-services reportviewer reportparameter

我有以下代码,我试图通过ReportViewer以编程方式创建xml报告。

Dim outputPath As String = "C:\backup\test.xml"
Dim reportViewer As New ReportViewer()
Dim serverReport As ServerReport = reportViewer.ServerReport()

reportViewer.ServerReport.ReportPath = "/<path>/<report>"
reportViewer.ServerReport.ReportServerUrl = New Uri("http://<ip>/reportserver")
reportViewer.ProcessingMode = ProcessingMode.Local

reportViewer.ServerReport.ReportServerCredentials.NetworkCredentials = New System.Net.NetworkCredential("<user>", "<pwd>")

Dim parameters As New List(Of ReportParameter)

parameters.Add(New ReportParameter("LocationLocationParent", "[Location].[Location Parent].&[2]"))
parameters.Add(New ReportParameter("CalendarYear", "[Calendar].[Year].&[2014-01-01T00:00:00]"))
parameters.Add(New ReportParameter("StaffStaffName", "[Staff].[Staff Name].&[Bob Smith]"))

Try
    serverReport.SetParameters(parameters)

    Dim mimeType As String = ""
    Dim encoding As String = ""
    Dim extension As String = ""
    Dim streams As String() = Nothing
    Dim warnings As Warning() = Nothing

    Dim xmlBytes As Byte() = serverReport.Render("XML", String.Empty, mimeType, encoding, extension, streams, warnings)

    Using fs As FileStream = New FileStream(outputPath, FileMode.Create)
        fs.Write(xmlBytes, 0, xmlBytes.Length)
        fs.Close()
    End Using

Catch reportEx As ReportServerException
    Debug.Print(reportEx.Message)
End Try

我在设置LocationLocationParent的参数时,不允许我按名称设置值,只能通过列表中每个值的某种索引类型设置。 SSRS报告本身的下拉列表采用树状结构,如下所示:

Parent1
    Parent2
        Parent4
            Child1
            Child2
        Parent5
            Child3
            Child4
        Child5
    Parent3
        Child5
        Child6

这个列表不是真正的树,只是看起来像一个。它是一个多选复选框项列表。我无法将参数设置为值&#34; Child3&#34;例如 - 仅通过其索引,但报表窗口的列表中有100个值。如果我这样设置: &#34; [位置]。[位置家长]。&amp; [Child3]&#34;我得到以下异常

此报告需要报告参数&#39; LocationLocationParent&#39;的默认值或用户定义值。要运行或订阅此报告,您必须提供参数值。 (rsReportParameterValueNotSet)

请注意,StaffStaffName参数不是在树状结构中形成的,只是一个列表,因此我能够正确设置该参数。

如何设置LocationLocationParent所需的值的名称?

0 个答案:

没有答案