使用数据表作为数据源填充Web reportviewer

时间:2013-06-01 00:28:56

标签: asp.net reportviewer

我使用ASP.NET 4.5和reportviewer版本11在本地模式下运行基于Web的reportviewer。我想用数据表填充它。数据表已填充,但是当我运行报表时,只有工具栏显示没有报表或显示错误。

这是我的代码:

    Protected Sub ButtonRunReport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ButtonRunReport.Click

ReportViewer1.Reset()
                ReportViewer1.LocalReport.ReportPath = "LMS/ParticipantListSummary.rdlc"
                ReportViewer1.LocalReport.DataSources.Clear()
                ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("LMS_ParticipantListSummary", GetDataTable("Participant List")))

ReportViewerDiv.Visible = True
        ReportViewer1.LocalReport.SetParameters(parameters)
                ReportViewer1.Visible = True
                ReportViewer1.Style.Item("display") = ""
                PanelOpeningMessage.Style.Item("display") = "none"
                ReportViewer1.LocalReport.Refresh()
End Sub

Private Function GetDataTable(ByVal reportType As String) As DataTable

        Dim dt As New DataTable
        Dim connectionString = ConfigurationManager.ConnectionStrings("LMSConnectionString").ConnectionString

        Dim cmdText As String = ... //command text string not shown.

        Using cn As New SqlConnection(connectionString)

        Dim dt As New DataTable()

        Dim state As ConnectionState = connection.State

        Dim adapter As New SqlDataAdapter(cmdText, cn)

        If state = ConnectionState.Closed Then
            connection.Open()
        End If

        adapter.Fill(dt)

        If state = ConnectionState.Open Then
            connection.Close()
        End If
        End Using

    return dt
End Function

有什么想法吗?

谢谢,贾斯汀。

P.S。忘了提一下,这在Reportviewer的第10版上运行良好。

1 个答案:

答案 0 :(得分:0)

问题解决了!

我有一个流氓reportviewer.visible = false导致报告无法呈现给浏览器。

在升级到asp.net 4.5和reportviewer 11之前,仍然不确定为什么会有效。