【问题标题】:Having issues with Crystal Reports not reflecting changes from SQL DBCrystal Reports 的问题无法反映 SQL DB 的更改
【发布时间】:2019-02-25 03:54:31
【问题描述】:

我对在 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。谢谢大家!

【问题讨论】:

  • 你试过 CrystalReportViewer1.DataBind() 吗? CrystalReportViewer1.RefreshReport()
  • Grid 事件后页面是否刷新?
  • @SreenathGanga 我已经尝试了这两行代码并且它正在工作,但是,在看到更新的报告之前,应用程序会提示数据库登录。如何在无需将数据库凭据放入后端代码的情况下查看更新的报告?
  • @JulyOrdinary 是的。我在事件之后绑定数据。
  • @Brian.Scalabrine 查看更新的答案

标签: asp.net vb.net gridview crystal-reports visual-studio-2017


【解决方案1】:

谢谢大家的建议。我可以通过将其添加到我的 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()

【讨论】:

    【解决方案2】:

    使用 getreport() 函数创建一个用于设置 Crystal 报表的登录值的类,该函数返回给定报表位置中 Crystal 报表的报表文档

     Module Logonvalues
        Function getpeport(ByVal ReportLocation As String) As ReportDocument
            Dim crconnectioninfo As ConnectionInfo = New ConnectionInfo()
            Dim cryrpt As ReportDocument = New ReportDocument()
            Dim crtablelogoninfos As TableLogOnInfos = New TableLogOnInfos()
            Dim crtablelogoninfo As TableLogOnInfo = New TableLogOnInfo()
            Dim CrTables As Tables
            cryrpt.Load(ReportLocation)
            cryrpt.DataSourceConnections.Clear()
            crconnectioninfo.ServerName = "ur servername"
            crconnectioninfo.DatabaseName = "ur database"
            crconnectioninfo.UserID =  "ur database username"
            crconnectioninfo.Password = "ur database password"
            CrTables = cryrpt.Database.Tables
    
            For Each CrTable As CrystalDecisions.CrystalReports.Engine.Table In CrTables
                crtablelogoninfo = CrTable.LogOnInfo
                crtablelogoninfo.ConnectionInfo = crconnectioninfo
                CrTable.ApplyLogOnInfo(crtablelogoninfo)
            Next
    
            Return cryrpt
        End Function
    End Module
    

    最后我们从水晶reportviewer组成的表单中调用登录值

    Public Sub loadreport()
        Crvt_ApplicationReport.ReportSource = Logonvalues.getpeport("yourlocation")
        Crvt_ApplicationReport.SelectionFormula = "yourformula if any"
        Crvt_ApplicationReport.RefreshReport()
    End Sub
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-17
      • 2014-11-25
      • 1970-01-01
      相关资源
      最近更新 更多