Crystal 报告有问题,未反映来自 SQL 数据库的更改
Having issues with Crystal Reports not reflecting changes from SQL DB
我对在 Visual Studio 2017 年使用 Crystal 报告创建报告有点陌生。
我使用设置向导在 VS2017 上创建了一个名为 PersonnelListingReport.rpt 的报告。通过向导,我选择了报告所基于的 table。此外,我添加了一个过滤器参数,该参数将仅显示活跃的员工,即(活跃 = 1,不活跃 = 0)。所以现在在我的主报告预览 window 中,我可以看到状态 = 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
这是我在 ReportViewer 的 aspx 下的内容:
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>
我的代码中是否遗漏了什么?我尝试按照论坛 posts 使用 Refresh() 和 Load() 解决类似问题,但无济于事。我还阅读了关于创建 Page_Unload 的论坛 post 然后让报告调用 Close() 然后 Dispose() 但也无济于事。我尝试选中复选框以在加载报告时丢弃已保存的数据,但仍然没有。我知道我遗漏了一些东西,但不太确定,因为这是我第一次在 Visual Studio 2017 年使用 Crystal 报告。谢谢大家!
谢谢大家的建议。我能够通过将此添加到我的 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()
创建一个 class 以使用函数 getreport() 为 Crystal 报告设置登录值,其中 returns 给定 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 报表查看器
组成的表单中调用登录值
Public Sub loadreport()
Crvt_ApplicationReport.ReportSource = Logonvalues.getpeport("yourlocation")
Crvt_ApplicationReport.SelectionFormula = "yourformula if any"
Crvt_ApplicationReport.RefreshReport()
End Sub
我对在 Visual Studio 2017 年使用 Crystal 报告创建报告有点陌生。 我使用设置向导在 VS2017 上创建了一个名为 PersonnelListingReport.rpt 的报告。通过向导,我选择了报告所基于的 table。此外,我添加了一个过滤器参数,该参数将仅显示活跃的员工,即(活跃 = 1,不活跃 = 0)。所以现在在我的主报告预览 window 中,我可以看到状态 = 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
这是我在 ReportViewer 的 aspx 下的内容:
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>
我的代码中是否遗漏了什么?我尝试按照论坛 posts 使用 Refresh() 和 Load() 解决类似问题,但无济于事。我还阅读了关于创建 Page_Unload 的论坛 post 然后让报告调用 Close() 然后 Dispose() 但也无济于事。我尝试选中复选框以在加载报告时丢弃已保存的数据,但仍然没有。我知道我遗漏了一些东西,但不太确定,因为这是我第一次在 Visual Studio 2017 年使用 Crystal 报告。谢谢大家!
谢谢大家的建议。我能够通过将此添加到我的 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()
创建一个 class 以使用函数 getreport() 为 Crystal 报告设置登录值,其中 returns 给定 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 报表查看器
组成的表单中调用登录值Public Sub loadreport()
Crvt_ApplicationReport.ReportSource = Logonvalues.getpeport("yourlocation")
Crvt_ApplicationReport.SelectionFormula = "yourformula if any"
Crvt_ApplicationReport.RefreshReport()
End Sub