首页 > 解决方案 > Crystal Reports 的问题无法反映 SQL DB 的更改

问题描述

我对在 Visual Studio 2017 上使用 Crystal Reports 创建报表有点陌生。我使用设置向导在 VS2017 上创建了一个名为 PersonnelListingReport.rpt 的报表。通过向导,我选择了报告将基于的表。此外,我添加了一个过滤器参数,该参数将仅显示处于活动状态的员工,即(活动 = 1,非活动 = 0)。所以现在在我的主报告预览窗口中,我可以看到所有状态 = 1 的员工。我的问题是,当我在 GridView 上添加或删除项目时,更改不会反映在我的报告中。这是我的 Page_Load 中的内容:

Public Class PersonnelListingReportViewer
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim crystalReport As New ReportDocument()

    crystalReport.Load(Server.MapPath("PersonnelListingReport.rpt"))

    CrystalReportViewer1.ReportSource = crystalReport

End Sub

这是我在我的 aspx 下的 ReportViewer 的内容:

body>
<form id="form1" runat="server">
    <div>
        <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True" GroupTreeImagesFolderUrl="" Height="1202px" ReportSourceID="CrystalReportSource1" ToolbarImagesFolderUrl="" ToolPanelWidth="200px" Width="1104px" />
        <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
            <Report FileName="PersonnelListingReport.rpt">
            </Report>
        </CR:CrystalReportSource>
    </div>
</form>

我的代码中是否缺少某些内容?我已经尝试根据论坛帖子使用 Refresh() 和 Load() 有类似问题但无济于事。我还阅读了有关创建 Page_Unload 的论坛帖子,然后让报告调用 Close() 然后 Dispose() 但也无济于事。我试过选中复选框以在加载报告时丢弃保存的数据,但仍然没有。我知道我遗漏了一些东西,但不太确定,因为这是我第一次在 Visual Studio 2017 上使用 Crystal Reports。谢谢大家!

标签: asp.netvb.netgridviewcrystal-reportsvisual-studio-2017

解决方案


谢谢大家的建议。我能够通过将其添加到我的 Page_Load 来解决该问题:

Dim cryRpt As New ReportDocument
    Dim crtableLogoninfos As New TableLogOnInfos
    Dim crtableLogoninfo As New TableLogOnInfo
    Dim crConnectionInfo As New ConnectionInfo
    Dim CrTables As Tables
    Dim CrTable As Table

    cryRpt.Load(Server.MapPath("PersonnelListingReport.rpt"))

    With crConnectionInfo
        .ServerName = "0.0.0.0"
        .DatabaseName = "TestDB"
        .UserID = "user"
        .Password = "pw"
    End With

    CrTables = cryRpt.Database.Tables
    For Each CrTable In CrTables
        crtableLogoninfo = CrTable.LogOnInfo
        crtableLogoninfo.ConnectionInfo = crConnectionInfo
        CrTable.ApplyLogOnInfo(crtableLogoninfo)
    Next

    CrystalReportViewer1.ReportSource = cryRpt
    CrystalReportViewer1.RefreshReport()

推荐阅读