我正在使用 Crystl Report XI 和 WFP 查看器在窗口上查看报告。
我正在尝试使用 RefreshReport() 方法刷新我的 Crystal Report。但它得到了一个NULLReferanceException
在线Me.irRapportViewer.ViewerCore.RefreshReport()
。
如果我删除此行,报告会被加载,但它不是最新的。要获得最新的,我必须单击Refresh
查看器上的按钮。这就是为什么我需要从代码中刷新它。
下面是代码。我找不到我做错了什么。
Private Sub Window_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
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 startupPath As String = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName
cryRpt.Load(startupPath & "\Reports\IrReport2.rpt")
Dim connectionString As String = ConfigurationManager.ConnectionStrings("ReportConnStr").ConnectionString
Dim conn = New SqlConnectionStringBuilder(connectionString)
crConnectionInfo.ServerName = conn.DataSource
crConnectionInfo.DatabaseName = conn.InitialCatalog
crConnectionInfo.UserID = conn.UserID
crConnectionInfo.Password = conn.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
Me.irRapportViewer.ViewerCore.ReportSource = cryRpt
Me.irRapportViewer.ViewerCore.ReuseParameterWhenRefresh = True
Me.irRapportViewer.ViewerCore.RefreshReport()
End Sub
XAML 如下
<Window x:Class="IrRptWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cr="clr-namespace:SAPBusinessObjects.WPF.Viewer;assembly=SAPBusinessObjects.WPF.Viewer"
Title="IrRptWindow" Height="700" Width="800" WindowStartupLocation="CenterScreen">
<Grid>
<cr:CrystalReportsViewer Name="irRapportViewer" ToggleSidePanel="None"></cr:CrystalReportsViewer>
</Grid>
</Window>