supplying my own business object to crystal reports basic[simple]

G

giddy

hi,

Basically, Instead of getting data from an oledb database or something
I have simple classes that contain computed values that should go to a
crystal report.

How do I get Crystal reports Basic(visual studio 2008) to create a
report that takes an instance of my business object. I emphasize
instance because most of the tutorials I see statically link the
report to the database and it magically loads the data. I want to
supply the report and instance of my object only through code.

Is there a way to accomplish this?

I'm using C#, and Visual Studio 2008 Pro. but its a .NET 2.0 project
I'm working on.

I have the regular crystal reports basic that comes with VS.

thanks so much

Gideon
 
G

G.S.

hi,

Basically, Instead of getting data from an oledb database or something
I have simple classes that contain computed values that should go to a
crystal report.

How do I get Crystal reports Basic(visual studio 2008) to create a
report that takes an instance of my business object. I emphasize
instance because most of the tutorials I see statically link the
report to the database and it magically loads the data. I want to
supply the report and instance of my object only through code.

Is there a way to accomplish this?

I'm using C#, and Visual Studio 2008 Pro. but its a .NET 2.0 project
I'm working on.

I have the regular crystal reports basic that comes with VS.

thanks so much

Gideon

Forgive me if this is not going to be the best tutorial - I hope it
points you in the right direction
Note that this applies to CR that comes with VS2005.
1. When you're setting the data source inside the Crystal Reports (CR)
designer, one of the options is Project Data/.NET Objects. You should
be able to find your business class in that hierarchy - just select it
as your data source.
2. Here's the nice thing - you can select more than one class - BUT
you must link them in parent-child relationship using the "Links" tab
on the "Database Expert" tab or... I think that tab was directly
accessible via a menu item...
3. Once your datasources are set, you can design your report. You will
quickly see what the limitations are - if your class contains a
collection, that collection won't be immediately available. That's
where the "child" data source usually comes into play...
4. At run-time, when you're about to display the report, you need to
set its data source to actual object(s) (or collections of object(s))
of the class(es) that are report's data source(s). Here's example of
what one of my apps do:
List<MyBusinessClass1> rptSource1 = new List<MyBusinessClass1>();
List<MyBusinessClass2> rptSource2 = new List<MyBusinessClass12>();
....
business logic populates the two lists
....
crViewer.Report.Database.Tables[0].SetDataSource(rptSource1);
crViewer.Report.Database.Tables[1].SetDataSource(rptSource2);

I hope this helps.
 
G

giddy

Hi, GS. Thanks so much for your reply.

Forgive me if this is not going to be the best tutorial - I hope it
points you in the right direction

Its pointing me very close. =)
...
crViewer.Report.Database.Tables[0].SetDataSource(rptSource1);
crViewer.Report.Database.Tables[1].SetDataSource(rptSource2);
What is crViewer?

crystalReportViewer1.Report.Database.Tables[0].SetDataSource(rptSource1);

In my code tells me :
'CrystalDecisions.Windows.Forms.CrystalReportViewer' does not contain
a definition for 'Report' and no extension method 'Report' accepting a
first argument....................


Did you make a typo, or is the Report some other object's property?

This seems to work:
List<Person> ps = new List<Person>();
ps.Add(new Person("Gideon",15));
CrystalReport11.SetDataSource(ps);
crystalReportViewer1.ReportSource = CrystalReport11;

Thanks so much

Gideon
 
G

G.S.

Hi, GS. Thanks so much for your reply.
Forgive me if this is not going to be the best tutorial - I hope it
points you in the right direction

Its pointing me very close. =)
...
crViewer.Report.Database.Tables[0].SetDataSource(rptSource1);
crViewer.Report.Database.Tables[1].SetDataSource(rptSource2);

What is crViewer?

crystalReportViewer1.Report.Database.Tables[0].SetDataSource(rptSource1);

In my code tells me :
'CrystalDecisions.Windows.Forms.CrystalReportViewer' does not contain
a definition for 'Report' and no extension method 'Report' accepting a
first argument....................

Did you make a typo, or is the Report some other object's property?

This seems to work:
            List<Person> ps = new List<Person>();
            ps.Add(new Person("Gideon",15));
            CrystalReport11.SetDataSource(ps);
            crystalReportViewer1.ReportSource = CrystalReport11;

Thanks so much

Gideon

My apologies - I didn't realize that crViewer is a user control that I
wrote... not the actual CRViewer object.

But it looks like you got it right.

Note that you need to go throught the Database collection if you have
more than one "table" (business object/collection) in your report.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top