Click here to Skip to main content
12,690,575 members (32,322 online)
Rate this:
Please Sign up or sign in to vote.

On my CR, I can display all data thru crystal report but once filter by show message 'invalid report file path' display data have been show.

Here my code:
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim rpt As New ReportDocument
        rpt.SetDatabaseLogon("sa1", "sa1")
        Me.CrystalReportViewer1.ReportSource = rpt
    End Sub

 Protected Sub btnReload_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnReload.Click
        ' Create filter expression, based on the filter input fields.
        ' If an input field is left blank, it isn't used in the filter expression.
        Dim filterString As String = Nothing
        AddFilter(filterString, "EmpNo", TextBox1, "'")
        AddFilter(filterString, "DeptmtID", TextBox2, "'")
        Dim rpt As New ReportDocument
        CrystalReportViewer1.ReportSource = rpt
        End Sub

 Private Sub AddFilter(ByRef filterString As String, ByVal databaseFieldName As String, ByVal fieldInput As TextBox, ByVal valueQuoteChar As String)
        Dim fieldValue As String = fieldInput.Text.Trim()

        ' If input field left blank, don't filter on it.
        If fieldValue = "" Then
        End If

        ' Escape for quotes if we're going to quote the value
        Dim escapedFieldValue As String = fieldValue
        If valueQuoteChar = "'" Then
            escapedFieldValue = fieldValue.Replace("'", "''")
        End If

        ' Add boolean clause to the complete filter expression
        ' This method always uses operator =
        Dim booleanSqlExpression As String = "{" & databaseFieldName & "} = " & valueQuoteChar & escapedFieldValue & valueQuoteChar

        ' separate boolean clauses with AND operator
        If Not String.IsNullOrEmpty(filterString) Then
            filterString += " AND "
        End If
        filterString += booleanSqlExpression
    End Sub

    Private Function CreateCrystalReportDocument(ByVal filterString As String) As ReportDocument
        Dim rpt As New ReportDocument()

        Dim report As String = Server.MapPath("CrystalReport1.rpt")

          ' ---- Assign connection information for each table in the database

        'Build connection info
        Dim crConnectionInfo As New ConnectionInfo
        crConnectionInfo.ServerName = "\BOSS_NET_DB"
        crConnectionInfo.DatabaseName = "eExitPass"
        crConnectionInfo.UserID = "sa1"
        crConnectionInfo.Password = "sa1"

        ' Assign to all tables used by the report
        Dim tables As Tables = rpt.Database.Tables
        For Each table As CrystalDecisions.CrystalReports.Engine.Table In tables
            Dim crtableLogoninfo As TableLogOnInfo = table.LogOnInfo
            crtableLogoninfo.ConnectionInfo = crConnectionInfo

        rpt.DataDefinition.RecordSelectionFormula = filterString
        Return rpt
    End Function

Posted 2-Jun-11 19:03pm
Updated 2-Jun-11 20:25pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You might want to set a breakpoint a couple of lines before the code bombs. I think you'll find your mistake quite easily. It may have something to do with not loading a report after you create a new ReportDocument.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

There may be couple of reasons, Troubleshoot your issue by the below link.

Crystal Reports - Invalid report file path[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170117.1 | Last Updated 3 Jun 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100