Data Connectivity
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Data Connectivity
Message Icon Topic: Alter sql at runtime Post Reply Post New Topic
Author Message
genvej
Newbie
Newbie


Joined: 06 Feb 2009
Online Status: Offline
Posts: 1
Quote genvej Replybullet Topic: Alter sql at runtime
    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.
IP IP Logged
jkwrpc
Senior Member
Senior Member


Joined: 19 Jun 2007
Location: United States
Online Status: Offline
Posts: 432
Quote jkwrpc Replybullet 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.
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3701
Quote hilfy Replybullet 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
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.033 seconds.