Print Page | Close Window

changing field data source programmatically

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Writing Code
Forum Discription: .NET programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=1857
Printed Date: 15 May 2024 at 2:43am


Topic: changing field data source programmatically
Posted By: jovball
Subject: changing field data source programmatically
Date Posted: 10 Dec 2007 at 4:59am
I am looking for a programmatic way to change the report data source and field data source for a report. I bought your book several years ago and have used it a lot but I don't see anything that quite gets me what I'm looking for here.

Here is the scenario. I have a report that is using direct SQL. To simplify the explanation, let's say that I am using Northwind and the data is coming from Customers and Orders tables. On the report are Customers.CustomerId, customers.companyName, Orders.OrderId and Orders.OrderDate.

I want to change the report data source to a stored procedure or a .NET dataset without having to rebuild the report. Again, for the sake of simplicity, we'll say that the new datasource is named CustomerOrders. So after the change, the report should have the CustomerOrders.CustomerId, CustomerOrders.companyName, CustomerOrders.OrderId and CustomerOrders.OrderDate as the fields.

Any help would be appreciated. If there is a way to do this via the user interface, that would be OK too.





Replies:
Posted By: BrianBischof
Date Posted: 10 Dec 2007 at 8:47pm
You can't do it programatically b/c the report has an internal method of connecting to each type of data source. You can't cross over. You should be able to do it from the CR interface. Choose the menu option Set Location and open the new datasource. Match up the individual tables and click the Replace button. I haven't tried to switch from SQL to a dataset, but it definitely works going from a table to a stored procedure. I discuss this in my CR.NET Programming book starting on page 254.

-------------
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>


Posted By: jovball
Date Posted: 11 Dec 2007 at 6:57am
I read this section of the book but it doesn't really do what I want. For example,  a report uses 5 tables and I re-map the fields to a dataset. The report still shows the 5 tables as the datasource. The dataset shows as the source instead of the database/ODBC connection, etc.

I want the various tables to go away, period.


Posted By: BrianBischof
Date Posted: 11 Dec 2007 at 11:51am
Not sure.... If you create a single dataset with all the necessary fields and then you map the report to the dataset, can't you then delete all the tables once the mapping is done? I always just do one-to-one replacements and never tried actually eliminating tables. So you'll have to experiment a bit with it and let us know how it goes.

-------------
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>



Print Page | Close Window