Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: changing field data source programmatically Post Reply Post New Topic
Author Message
jovball
Newbie
Newbie


Joined: 10 Dec 2007
Location: United States
Online Status: Offline
Posts: 3
Quote jovball Replybullet Topic: changing field data source programmatically
    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.


IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet 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.

Edited by BrianBischof - 10 Dec 2007 at 8:48pm
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
jovball
Newbie
Newbie


Joined: 10 Dec 2007
Location: United States
Online Status: Offline
Posts: 3
Quote jovball Replybullet 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.
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet 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>
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.