Print Page | Close Window

Alter sql at runtime

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Data Connectivity
Forum Discription: How to connect to data sources and export reports
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=5436
Printed Date: 06 May 2024 at 12:41am


Topic: Alter sql at runtime
Posted By: genvej
Subject: Alter sql at runtime
Date Posted: 06 Feb 2009 at 2:08am

Im brand new to crystal reports and have some problems.

I have made a report as i like it with subreports and more. Im now ready to fill in the relevant data with where clauses and the likes.
 
Im just confused about the whole parameter thingy, so im more interested in altering the sql statements on my report at runtime. Is there any way this can be done? Im thinking about something like:
 
CrystalReport1 report=new CrystalReport();
string sql=report.getSql();
sql+=" where id in (1,2,3)"
report.setSql(sql);
report.ReportSource=report;
 
I just dont seem to be able to find the methods to do this.



Replies:
Posted By: jkwrpc
Date Posted: 13 Feb 2009 at 12:51pm

Here is my limited understanding:

To use CR methods to select the records you need to use the Selection Formula. That takes the CR syntax and converts it to SQL to run against the dbms.
 
To run a SQL statement you would need to use something like a dataset to contain the results and then use the dataset as the reports data source.
 
You can probe the CR Viewer and Report Document object models for the various properties.
 
I have come to a point where I try to utilize the inherent power of CR as much as possible. Seems simpler to me.  I only use things such as datasets when there is no other viable alternative to getting the level of data control I need.
 
Regards,
 
John W.
http://www.CustomReportWriters.net - www.CustomReportWriters.net


Posted By: hilfy
Date Posted: 13 Feb 2009 at 1:29pm

You can't alter the whole SQL directly.  However, if you look at the help for the RecordSelectionFormula property of the ReportDocument class, you should be able to set the selection criteria there.

-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics



Print Page | Close Window