1

Crystl Report XIとWFPビューアを使用して、ウィンドウにレポートを表示しています。

RefreshReport()メソッドを使用してCrystalReportを更新しようとしています。しかし、それは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()ビューアにレポートを設定する前に試してみました。以下は、ウィンドウロードイベントの最後の3行を変更したものです。

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 に答える