在WPF中刷新Crystal Report时出现异常 [英] Getting exception on refreshing the Crystal Report in WPF

查看:52
本文介绍了在WPF中刷新Crystal Report时出现异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Crystl Report XI和WFP查看器在窗口上查看报告。

I am using Crystl Report XI and WFP viewer to view the report on a window.

我正在尝试使用RefreshReport()方法刷新Crystal报表。但是它在 Me.irRapportViewer.ViewerCore.RefreshReport()行中获得 NULLReferanceException

I am trying to refresh my Crystal Report using the RefreshReport() method. But it gets a NULLReferanceException at the line Me.irRapportViewer.ViewerCore.RefreshReport().

如果我删除这一行,报告将被加载,但不是最新的。要获取最新版本,我必须在查看器上单击 Refresh 按钮。这就是为什么我需要从代码中刷新它的原因。

If i remove this line the report gets loaded but its not the latest one. To get the latest one i have to click on the Refresh button on the viewer. Thats why I need to refresh it from the code.

下面是代码。我找不到我在做什么错。

Bellow is the code. I can't find what I am doing wrong.

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>


推荐答案

看了几个小时之后,终于想到了为什么而不是尝试刷新 ReportDocument ,而且效果惊人。在将报告设置为查看器之前,我尝试过 cryRpt.Refresh()。以下是修改后的窗口加载事件的最后三行。

After hours of looking here and there finally I thought why not try refreshing the ReportDocument and amazingly it works. I tried cryRpt.Refresh() before setting the report to the viewer. Following are the modified last three lines of my window load event.

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

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

在此答案下,您可以发表评论。

Comments are appreciated under this answer.

这篇关于在WPF中刷新Crystal Report时出现异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆