Select criteria not working in Crystal Reports and Visual Studio 2010

crystal-reportsvisual studio 2010

I have inherited an existing Crystal Report (.rpt) for a report that prints all records in the relevant dataset.

I now want to add selection criteria such that only the results with a matching ticket number are printed on the report.

The selection criteria I have entered is:

{REGISTER.TICKET_NO} = {?sTicketNo}

sTicketNo reflects a text value that I read from a text box in C# and pass to Crystal Reports as parameter. (The parameter passing definitely works. When I add the sTicketNo field to the report, it prints the correct value that I entered in the text box).

The problem is that no matter what selection criteria I enter, the reports never get filtered. It always prints ALL the records regardless of criteria. I have tested with other hard-coded criteria such as selecting only records with non-null values.

I have also tried the advice from C# and Crystal Reports SDK – Selection Criteria Ignored without success.

Is there perhaps anywhere else in Crystal Reports that you have to specify that you don't want all records printed? I have added my selection criteria in menu "Crystal Reports" > "Report" > "Select Expert" > "Record". I am very new to crystal reports. Maybe the author of the report added some setting elsewhere to ignore selection criteria, but I'm not sure where to look…

Best Answer

Had the same problem - found this solution. Worked for us for VS 2010 even though it mentions VS 2005/2008.

Symptom

When upgrading a VS .NET application to use Crystal Reports 2008 in Visual Studio .NET 2005, the selection formula (.RecordSelectionFormula) is ignored.

Cause

In Visual Studio .NET 2005, when the Crystal Windows Form Viewer is added to a Windows Form, the auto-generated code adds two lines of code that set the selection formula to an empty string (""). The viewer's SelectionFormula and ViewTimeSelectionFormula are set to "" by default, thus, the application will ignore selection formulas, be it in the report designer or passed to the report at runtime.

Resolution

To resolve the issue, follow these steps:

Expand Form1.vb|cs to show Form1.Designer.vb|cs. (form1 denotes the form that contains your viewer)

Double-click on Form1.Designer.vb|cs to show its code.

In the InitializeComponent method, you will find code where the CrystalReportViewer1 properties are set.

Comment out or delete the following two lines:

me.crystalReportViewer.SelectionFormula = ""

me.crystalReportViewer.ViewTimeSelectionFormula = ""
Related Topic