I am using Crystl Report XI and WFP viewer to view the report on a window.
I am trying to refresh my Crystal Report using the RefreshReport() method. But it gets a NULLReferanceException
at the line Me.irRapportViewer.ViewerCore.RefreshReport()
.
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
The XAML is as bellow
<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>