SAP Knowledge Base Article - Public

1290058 - How to filter the data without hitting the database again, once the data is fetched from the database.

Symptom

The Crystal report is supposed to bring in all the data from a table or tables, based on the report designed in Crystal Report designer, but only selected data is to be displayed by the ReportViewer control in a .NET application.

Reproducing the Issue

  • Crystal Reports XI Release 2.
  • Visual Studio 2003.

Resolution

Using the ViewTimeSelectionFormula property of the CrystalReportViewer control, to filter data, just before displaying the selected data, in the report, not only reduce the number of hits to the database but also display the required data to the user. So the report brings all the data from the database and the Viewer control filters the data before displaying it on the report.

Code to use this property: 

// creating a report object (in VS-2003)
MyReport Report = new MyReport();

// Applying the filter for the data to be displayed. for eg. "DATE({Orders.OrderDate}) <= #8/1/1996#";
CrystalReportViewer.ViewTimeSelectionFormula = "DATE({Orders.OrderDate}) <= date_value";

// Displaying the report.
CrystalReportViewer.ReportSource = Report;

Note:

Using the Viewer Object Model and the ReportDocument Object Model interchangeably is not recommended.

Keywords

.net, filter data before viewing, vs2003, vs, cr, crxi , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To

Product

SAP Crystal Reports XI R2