Report Design
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Report Design
Message Icon Topic: creating dynamic reports / reports on the fly Post Reply Post New Topic
Author Message
roland12345
Newbie
Newbie
Avatar

Joined: 28 Sep 2008
Location: Canada
Online Status: Offline
Posts: 6
Quote roland12345 Replybullet Topic: creating dynamic reports / reports on the fly
    Posted: 28 Sep 2008 at 9:59am
Hello,

I need to create dynamic reports using Crystal 2008 inside of C# for a project I am working on. So the reports need to be created on the fly during runtime - The user is presented with all the fields from the table and they select two or three fields in the browser and the crystal report is created with only the selected fields displayed.

How do I go about doing this? I am trying to read documentation and it looks like I will be using the CrystalReportViewer object. Any samples / chunks of code would be much appreciated.

Thanks,
- Roland
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 28 Sep 2008 at 11:57pm
This is actually a pretty complex chunk of code (and too much to answer in a forum post). I just finished my CR.NET 2008 book and I talk about this in it. But it won't be in the bookstores till November 1st. If you want to check out the online version, it's Chapter 20. But this is membership only for access all my books online. However, I give members first priority when I have time to answer questions and people seem to appreciate this.
 
You can find out more about my books at Amazon.com or reading the Crystal Reports eBooks online.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
roland12345
Newbie
Newbie
Avatar

Joined: 28 Sep 2008
Location: Canada
Online Status: Offline
Posts: 6
Quote roland12345 Replybullet Posted: 29 Sep 2008 at 10:42am
I have looked at the book you offer, I will probably need a big reference document for crystal anyways so I will eventually have to decide on one.

For now, is there anything specifically I can look into that will lead me to the right direction, I think I should be using the crystal API to add fields dynamically onto the report? Is it done with CrystalReportViewer object or some other mechanism.

Thanks
Thanks
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 29 Sep 2008 at 11:53am
Hi Roland,
 
It's not the viewer, that just displays the report. You have to work with the specific report objects. First, add these references to your project:
CrystalDecisions.ReportAppServer.ClientDoc
CrystalDecisions.ReportAppServer.DataDefModel
CrystalDecisions.ReportAppServer.Controllers
CrystalDecisions.ReportAppServer.ReportDefModel
Next,  you have to do is create an instance of the report using the ReportDocument class. Then get a reference to the ReportClientDocument property and assign it to an object variable of the same type. This object variable is what controls dynamic report creation and modification. You can look at all the properties and methods of the ReportClientDocument class to see what is available.
 
You can find out more about my books at Amazon.com or reading the Crystal Reports eBooks online.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
roland12345
Newbie
Newbie
Avatar

Joined: 28 Sep 2008
Location: Canada
Online Status: Offline
Posts: 6
Quote roland12345 Replybullet Posted: 29 Sep 2008 at 12:12pm
ok, very good, I can work with that, that should be enough to give me a good starting point.

Right now we are using crystal 11 (I have posted a link to another solution below) which looks to work in Crystal 11 hopefully it must also work in crystal 2008 because we will be upgrading to 2008 shortly.

Here is the Other solution - http://www.c-sharpcorner.com/UploadFile/uditsingh/CR1111022006055359AM/CR11.aspx

I'm wondering if it works, it seems like it does. I'm wondering if there are any disadvantages to using that approach as apposed to the more modern way you suggest?

Thanks again
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 29 Sep 2008 at 6:46pm
This way is fine. The problem is that you have to define everything in advance and have the report built with all the fields. And you have to create a zillion formulas and manage them. With RAS you can just put what you want into the report. But this is fine and what most people do who don't want to work with RAS. If you do decide to go with RAS in the future, you need the XI R2 update. If you're using CR 2008, you will need the R0 release to make it compatible with .NET 2008.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
BernieHunt
Newbie
Newbie


Joined: 03 Apr 2007
Location: United States
Online Status: Offline
Posts: 21
Quote BernieHunt Replybullet Posted: 14 Oct 2008 at 5:44am
Roland,
 
As a programmer, I think you'll be much better off creating your reports in code rather than the other method.
 
The advantages of creating your reports in code is in the similarity between them. You will be able to create alot of multi use code for layout and such. If you use the other method, you'll be doing alot of work by hand. Depending on the number of possible fields the user can select, this could get out of hand quickly!
 
I would get Brians book or learn it on your own and then create the reports in code. Find the similarities between the method of using the various fields. I bet you could write the whole Crystal portion without the UI in less than 200 lines of code.
 
The other side benifit of coding the report is consistancy in look and feel. If I write code to put a column at x,y, then it's always there no mater what data I put in it. If I lay out the reports by hand, it's a pain to make sure everything lines up the same each and every time.
 
Just my experience from messing with this a while.
 
Bernie
IP IP Logged
roland12345
Newbie
Newbie
Avatar

Joined: 28 Sep 2008
Location: Canada
Online Status: Offline
Posts: 6
Quote roland12345 Replybullet Posted: 16 Oct 2008 at 8:49am

I got the core of it working now, (the samples in the business objects website were helpful, i.e. the one that is called adding a field dynamically into the report).

Anyways, I am trying to find out how to limit the number of records displayed in the crystal report, (because if I have a table that is selected that returns a million records, i want to limit it to 1000) isn't there a method for doing this like one line of code, I am having trouble finding it.

Thanks,
IP IP Logged
roland12345
Newbie
Newbie
Avatar

Joined: 28 Sep 2008
Location: Canada
Online Status: Offline
Posts: 6
Quote roland12345 Replybullet Posted: 21 Oct 2008 at 7:54am
Hi guys,

I am still having that one last issue where I need to restrict the results in the Crystal Report dynamically. I know I can place restrictions in the view, i.e. SELECT TOP 1000 FROM TABLE. but this poses two problems, one is that when I link tables together results will be cut off, the 2nd is that in our system we have 300 tables to report on and I don't want to create views for each one, right now I am reporting directly on the tables themselves but like I said if there are a million records the system freezes.

I think there is a technique for creating a group dynamically and using the GroupSort to filter (not sure if this works), but I'm pretty sure it won't work when I have linked tables.

Any thoughts?

Thanks,
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.031 seconds.