1

我正在使用 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>
4

1 回答 1

0

经过几个小时的到处寻找后,我终于想到为什么不尝试刷新它ReportDocument并且令人惊讶的是它的工作原理。我cryRpt.Refresh()在将报告设置给查看器之前尝试过。以下是修改后的我的窗口加载事件的最后三行。

cryRpt.Refresh()
Me.irRapportViewer.ViewerCore.ReportSource = cryRpt

'Me.irRapportViewer.ViewerCore.ReuseParameterWhenRefresh = True (No Need)
'Me.irRapportViewer.ViewerCore.RefreshReport() (No Need)

在此答案下感谢评论。

于 2012-04-19T07:14:11.857 回答