Skip to Content
0
Nov 11, 2015 at 10:11 AM

Change DataSource Dynamically

31 Views

HI Folks,

Using Crystal Reports for Visual Studio .

On my form, I can show a crystal report showing lets say a customer list. The data on the report comes from a stored procedure which was set up when the report was designed. This all works fine.

I was wondering if there was a way I could use the same report but dynamically use a different datasource....

On my form I would like to filter the customer list and have the report based on the filtered data, rather than the stored proc (which shows all the customers).

To filter the data, I am using ds.Tables[0].DefaultView.RowFilter = "countryID = FR";

But this returns a dataView. Not a dataTable. Can I send a dataview to the crystal report as a ddatasource?

When I did try and send a dataTable as the reports data source, it did not work.

Here was my code for setting the dataSource

ReportDocument rep = new ReportDocument();

rep.Load(Globals.pathToCrystalReports + reportName);

rep.SetDataSource(_ds.Tables[0]); // Error Here ********

rep.Refresh();

The error message is:

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll

Additional information: Could not load file or assembly 'file:///C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI

Perhaps this cannot be done ???

J