Search code examples
asp.netvb.netgridviewcrystal-reportsvisual-studio-2017

Having issues with Crystal Reports not reflecting changes from SQL DB


I'm kinda new to creating reports with Crystal Reports on Visual Studio 2017. I've created a report on VS2017 called PersonnelListingReport.rpt using the setup wizard. Through the wizard I've selected the table for which the report will be based on. Also, I added a filter parameter that will display only the Employees who are active i.e(Active = 1, Inactive = 0). So now in my Main Report Preview window I can see all of the employees with Status = 1. My issue is that when I Add or Delete an item on my GridView, the change does not reflect on my report. Here's what I have in my Page_Load:

Public Class PersonnelListingReportViewer
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim crystalReport As New ReportDocument()

    crystalReport.Load(Server.MapPath("PersonnelListingReport.rpt"))

    CrystalReportViewer1.ReportSource = crystalReport

End Sub

Here's what I have under my aspx for ReportViewer:

body>
<form id="form1" runat="server">
    <div>
        <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="True" GroupTreeImagesFolderUrl="" Height="1202px" ReportSourceID="CrystalReportSource1" ToolbarImagesFolderUrl="" ToolPanelWidth="200px" Width="1104px" />
        <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
            <Report FileName="PersonnelListingReport.rpt">
            </Report>
        </CR:CrystalReportSource>
    </div>
</form>

Is there something I am missing in my code? I've tried using Refresh() and Load() as per forum posts with similar issues but to no avail. Ive also read a forum post about creating a Page_Unload then have the report call the Close() and then Dispose() but also to no avail. Ive tried checking the checkbox to Discard Saved Data When Loading Reports but still nothing. I know I'm missing something but not quite sure as this is my first time using Crystal Reports on Visual Studio 2017. Thank guys!


Solution

  • Thanks guys for the advice. I was able to resolve the issue by adding this to my Page_Load:

    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 CrTable As Table
    
        cryRpt.Load(Server.MapPath("PersonnelListingReport.rpt"))
    
        With crConnectionInfo
            .ServerName = "0.0.0.0"
            .DatabaseName = "TestDB"
            .UserID = "user"
            .Password = "pw"
        End With
    
        CrTables = cryRpt.Database.Tables
        For Each CrTable In CrTables
            crtableLogoninfo = CrTable.LogOnInfo
            crtableLogoninfo.ConnectionInfo = crConnectionInfo
            CrTable.ApplyLogOnInfo(crtableLogoninfo)
        Next
    
        CrystalReportViewer1.ReportSource = cryRpt
        CrystalReportViewer1.RefreshReport()