Hi,
I have to print a report offline, where the result of the report doesn't exists into the DB.
I added the reference to CrystalDecisions.CrystalReports.Engine v2.0.50727 (version 12.0.2000.0) on my .Net Framework 4 project.
I runned the method that have to print the report, and save the dataset into an XML file:
internal void PrintData(string reportFile, string printerName)
{
DataTable DT = CreateDataTable();
if (DT.Rows.Count > 0)
{
DataSet DS = new DataSet();
DS.DataSetName = "ReportDataset";
DS.Namespace = "ReportNamespace";
DS.Tables.Add(DT);
DS.WriteXml(Environment.GetEnvironmentVariable("TEMP") + "\\ReportDataset.xml", XmlWriteMode.WriteSchema);
if (false)
{
ReportDocument report = new ReportDocument();
report.Load(reportFile);
report.SetDataSource(DS);
PrintDialog pd = new PrintDialog();
pd.PrinterSettings.PrinterName = printerName;
if (pd.ShowDialog() == DialogResult.OK)
{
report.PrintOptions.PrinterName = pd.PrinterSettings.PrinterName;
report.PrintToPrinter(1, false, 0, 0);
}
}
}
}
Then I create the Report with Crystal Reports 2008 (v12.0.0.683). I create the connection as a XML connection, to the XML file I created.
It seems to run.
I changed the
if (false)
into
if (true)
to see the result.
The statement
report.SetDataSource(DS);
throw an unhandled exception of type DataSourceException (Unknown error on database connector).
What I have tried:
I tried also to perform the print in Pull mode, and it runs well, but it's unelegant to write the xml file because Crystal Reports don't performs the SetDataSource method. There is something wrong in versions?