我有点新手,可以在Visual Studio 2017上使用Crystal Reports创建报告。我已经在VS2017上创建了一个名为PersonnellistReport.rpt的报告,使用设置向导。通过向导,我选择了报告将基于报告的表。另外,我添加了一个过滤器参数,该参数仅显示活跃的员工(活动= 1,intactive = 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 the Close(),然后distose(),但也无济于事。我试图在加载报告时检查复选框以丢弃保存的数据,但仍然没有。我知道我缺少一些东西,但不确定,因为这是我第一次使用Visual Studio 2017上的Crystal Reports。谢谢!
感谢大家的建议。我能够通过将其添加到我的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()
创建一个用于设置Crystal Report的登录值的类,它使用function getReport()返回在给定报告位置中返回Crystal Report的报告日志
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