Click here to Skip to main content
15,894,646 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

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

Here my code:
VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       Dim rpt As New ReportDocument
       rpt.Load(Server.MapPath("CrystalReport1.rpt"))
       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
           Return
       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")
       rpt.Load(report)

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

       'Build connection info
       Dim crConnectionInfo As New ConnectionInfo
       crConnectionInfo.ServerName = "10.1.2.215\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
           table.ApplyLogOnInfo(crtableLogoninfo)
       Next

       rpt.DataDefinition.RecordSelectionFormula = filterString

       Return rpt
   End Function

Thanks
Aleesya
Posted
Updated 2-Jun-11 19:25pm
v2

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.
 
Share this answer
 
There may be couple of reasons, Troubleshoot your issue by the below link.

Crystal Reports - Invalid report file path[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900