0

我有以下代码,我试图通过 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

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

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

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

如何为 LocationLocationParent 设置我想要的值的名称?

4

0 回答 0