Crystal Reports的问题不能反映SQL DB的更改

问题描述 投票:0回答:2

我是在Visual Studio 2017上使用Crystal Reports创建报表的新手。我使用设置向导在VS2017上创建了一个名为PersonnelListingReport.rpt的报表。通过向导,我选择了报告所基于的表格。另外,我添加了一个过滤器参数,该参数仅显示活动的Employees,即(Active = 1,Inactive = 0)。所以现在在我的主报告预览窗口中,我可以看到Status = 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.net vb.net gridview crystal-reports visual-studio-2017
2个回答
0
投票

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

0
投票

使用函数getreport()创建一个用于设置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

最后,我们将从包含crystal reportviewer的表单中调用登录值

Public Sub loadreport()
    Crvt_ApplicationReport.ReportSource = Logonvalues.getpeport("yourlocation")
    Crvt_ApplicationReport.SelectionFormula = "yourformula if any"
    Crvt_ApplicationReport.RefreshReport()
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.