Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Dynamic Crystal Report? Post Reply Post New Topic
Author Message
jobejufranz
Newbie
Newbie


Joined: 03 Mar 2008
Online Status: Offline
Posts: 3
Quote jobejufranz Replybullet Topic: Dynamic Crystal Report?
    Posted: 03 Mar 2008 at 11:16pm
Hi guys,
 
I'm new to this forum and new to Crystal Report itself. Basically i need help from you guys. Currently, i'm using vs 2005 pro in doing company's project.
 
I have a few questions to ask and hope i would be able to gain more insight about crystal report.
 
I'm currently doing asp.net 2.0 project where i need to prepare a report to be printed on the intranet. My question is that, is it possible to design a crystal report then populate the fields dynamically without using DataSource? I'm doing this because i have several tables to link, some tables requires only 1 row and others requires at least 5 rows. I can already pull out everything I need on my code and i am planning to simply pass all this data from a DataTable/DataSet to a pre-formatted CrystalReport then load CrystalReportViewer on another page.
 
Forgive me guys, my knowledge in Crystal Report is very poor. I hope i can learn more on this forum and develop my skills in crystal report.
 
Any help would be highly appreciated. TIA.
 
 
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 03 Mar 2008 at 11:42pm
Yes, it is easy to report from a dataset object (well, it's easy after you do it once or twice...) The first step is to temporarily populate you DataSet with actual data you plan on reporting from. Then save it to an XML Schema file using DataSet.WriteXmlSchema(). Once you've done that you don't need that code anymore.

Next, you want to create the report and for the data source, choose ADO.NET and open the schema file you just saved. CR reads the schema file to determine the fields you want to report from. Finish building your report using this schema file as the data source.

Last, in your live application open the report and pass the fully populated dataset to the report using the SetDataSource() method. CR takes this data and prints it on your report.

Caution: The schema file must match the DataSet exactly. The slightest change will cause CR to not recognize your dataset. If you have to modify the dataset in anyway, then go through the steps to re-create the schema file and have CR read it again using Database | Set Location menu option.
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
jobejufranz
Newbie
Newbie


Joined: 03 Mar 2008
Online Status: Offline
Posts: 3
Quote jobejufranz Replybullet Posted: 04 Mar 2008 at 12:28am
Thanks for the reply Brian.
 
So everytime i pull out my data, I will need to generate an XML Schema? And this XML Schema will be passed to the Crystal Report as a DataSource? Am i right to say that?
 
Another question. Is it possible for me to dynamically assign a value from a DataSet/DataTable to Crystal Report fields?
 
e.g.
 
Text3 = ds.Table(0).Row(0).Item(0).toString
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 04 Mar 2008 at 1:10am
You only need to refresh the scema file if the underlying data structure changes. If you're just loading different data (but using the same fields), then you're okay to just keep passing the new dataset to the report.

Yes, you can assign any value to a text field.
Imports CrystalDecisions.CrystalReports.Engine
Dim MyText as TextObject
MyText = CType(ReportDocument.ReportDefinition.ReportObjects("Text3"), TextObject)
MyText.Text = "'" & ds.Table(0).Row(0).Item(0).ToString() & "'"

Make sure you surround and strings with the single quote, otherwise you get an error because it thinks you are trying to pass it a variable name.
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
jobejufranz
Newbie
Newbie


Joined: 03 Mar 2008
Online Status: Offline
Posts: 3
Quote jobejufranz Replybullet Posted: 04 Mar 2008 at 10:21pm
Originally posted by BrianBischof

You only need to refresh the scema file if the underlying data structure changes. If you're just loading different data (but using the same fields), then you're okay to just keep passing the new dataset to the report.

Yes, you can assign any value to a text field.
Imports CrystalDecisions.CrystalReports.Engine
Dim MyText as TextObject
MyText = CType(ReportDocument.ReportDefinition.ReportObjects("Text3"), TextObject)
MyText.Text = "'" & ds.Table(0).Row(0).Item(0).ToString() & "'"

Make sure you surround and strings with the single quote, otherwise you get an error because it thinks you are trying to pass it a variable name.
 
Thanks for reply BrianBischof.
 
Though XMLSchema might be the solution but I don't have enough time now to prepare the schema.
 
Anyway, the code that you have given me is the one that i'm looking for though i had to instantiate a DocumentReport and point it to the CrystalReport file in order to access the Text3.

Dim
oRpt As ReportDocument = New ReportDocument
oRpt.Load(Server.MapPath(
"BasicReport.rpt"))

Dim
MyText As TextObject
MyText =
CType(oRpt.ReportDefinition.ReportObjects("Text3"), TextObject)

MyText.Text =
"This is my sample text"
CrystalReportViewer1.ReportSource = oRpt 
 
I think I can already start from here. IMHO, i consider this forum as the best so far. A million thanks BrianBischof Star. Keep it up. Clap


Edited by jobejufranz - 04 Mar 2008 at 10:23pm
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 05 Mar 2008 at 1:16am
Glad you like the forum. Spread the word!
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
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.