Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error setting filter condtion at runtime on ReportDocument object...

Status
Not open for further replies.

bgravi

Programmer
Jul 28, 2002
15
0
0
US
I am having problems filtering records at runtime thru the ReportDocument object. I am using CR with VS.Net
Once the report loads the data and it is displayed, and if I have to change the record when the user selects a criteria for filtering it, then it doesn't work. The following piece of code does not work...

public void filterButton_Click( object sender, System.EventArgs e )
{
ReportDocument rd = crystalReportViewer1.ReportSource as ReportDocument ;
if( rd ! = null )
{
rd.DataDefinition.RecordSelectionFormula = "{myView.FirstName} = 'Jane' " ; //this doesn't work
rd.Refresh() ; //this too doesn't work
crystalReportViewer1.RefreshReport();
}


}


The above function does not work and I don't know why!!! It is legal code and is as per the sample documentation. Now, if I set the CrystalReportViewer's SelectionFormula value, that works. If I switch on my profiler and look at the query being sent to the database after changing the RecordSelectionFormula of the ReportDocument/DataDefinition object, it doesn't contain the new condition. But if I set the viewer's selection formula, they I can see the query with the new condition being sent to the database. Why does RecordSelectionFormula work with the viewer and not the Document/DataDefinition object? My requirement is such that I need it work off the ReportDocument object. I don't have any Record/group selection formula at design time.


Second question,
If there is already a record selection formula at design time, then the viewer.SelectionFormula shows this value and not the ReportDocument.RecordSelectionFormula. Why is this so? In such a case, if the RecordSelection formula of the ReportDocument is set at runtime, then which selection formula does CR choose to filter the records? The one set in viewer object( at design time thru designer ) or the one set at runtime thru the ReportDocument object?


Thank you,
Ravi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top