Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing XML data source of Crystal Report

I created a Crystal Report and connected it to an XML file at C:\SomeDir\Data.xml.

At runtime, I may need to put the data in C:\SomeOtherDir\Data.xml.

The code I have so far looks like this:

ReportDocument report = new ReportDocument();
report.Load("Report.rpt");
PrinterSettings printerSettings = new PrinterSettings();
PageSettings pageSettings = printerSettings.DefaultPageSettings;
report.PrintToPrinter(printerSettings, pageSettings, false);

That will print the report with the data at C:\SomeDir\Data.xml. I want it to print the data at C:\SomeOtherDir\Data.xml.

How can I do this?

like image 539
Kendall Frey Avatar asked Nov 14 '22 03:11

Kendall Frey


1 Answers

ReportDocument report = new ReportDocument();
report.Load("Report.rpt");

DataSet reportData = new DataSet();
reportData.ReadXml(@"C:\SomeOtherDir\Data.xml");
report.SetDataSource(reportData);

PrinterSettings printerSettings = new PrinterSettings();
PageSettings pageSettings = printerSettings.DefaultPageSettings;
report.PrintToPrinter(printerSettings, pageSettings, false);

If the schema of the XML changes, you will need to open the report in the CR editor and "verify database" to update the schema it is bound to, or it will throw the mysterious "Logon Failed" error.

like image 172
DaveMorganTexas Avatar answered Dec 16 '22 03:12

DaveMorganTexas