Print Page | Close Window

.Net objects as datasource, problem linking data

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
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=4953
Printed Date: 29 Apr 2024 at 1:57am


Topic: .Net objects as datasource, problem linking data
Posted By: Gotham
Subject: .Net objects as datasource, problem linking data
Date Posted: 08 Dec 2008 at 2:33pm
Hi all!

I have a little problem using .NET objects as a datasource for a report.

I want to be able to output an ordinary invoice with an order-head and order-items. The head contains information about the customer, deliveryaddresses and such. The order items are a collection of products bought by the related customer. And a summary at the bottom of the report.

I've created and successfully deployed a working version of the report using a .NET DataSet (XSD with tables Orders and OrderItems linked in it) but I want to do the same using .NET objects (custom classes and collections).

Preps:
I've started from scratch with the report and created the classes Order and OrderItem containing the relevant properties.

Order
 - OrderNr (primary key)
 - CustomerName

OrderItem
 - OrderNr (foreign key)
 - ProductName
 - Qty

Report design:
I'm able to import the objects (Order and OrderItem) into the report and link them together (not sure that I'm doing it right though).
I've dragged some Order-properties to the Page Header, and some OrderItems-properties to a Details section.
I've tried a couple of group-settings but I'm not sure I'm setting this up right either. Removed for now.

Runtime:
I create an instance of Order and set the values, then create an number of instances of OrderItem and set the values accordingly (OrderNr=same).
Then I wrap the Order in an ArrayList and call SetDataSource on the report. Next I wrap the instances of OrderItems in an ArrayList and call SetDataSource directly after the first. Is this ok?

Result:
Based on what data I add I can see the Order-data in the Head. But never any OrderItems an certainly not both at the same time. What am I doing wrong?
How does one go about and use .NET Objects as datasource in the way I want?

Sidenote:
When I close the Database Expert I get the following message:
"More than one datasource ... has been used in this report. Please make sure that no SQL Expression is added and no server-side group-by is performed."

Environment:
* VS.NET 2008
* Crystal Reports for VS.NET 2008
* ReportViewer (WinForms)

Kind regards
/ Richard



Replies:
Posted By: jamshid.gh
Date Posted: 07 Jul 2011 at 9:10pm
Hi,
you must Set Data Source for all Objects.
like:
CrystalReportObject.Database.tables[0].SetDataSource(order);
CrystalReportObject.Database.tables[1].SetDataSource(orderItems);




Print Page | Close Window