Question

I implemented a loop that exports a crystal report to pdf. The idea is instanciating the initial report with its conection and then inside the loop applying the parameters before exporting to PDF (so i get one pdf for each record), but the report keeps exporting the pdf with the data of the first loop execution. How can i force it to refresh its data after applying the new parameters?

Example Code:

ReportDocument reportDoc=new ReportDocument();
reportDoc.Load("c:\\reportx.rpt");
ConnectionInfo cinfo = FunctionLibrary.getCrystalConection();
foreach (Table table in reportDoc.Database.Tables)
{
    table.LogOnInfo.ConnectionInfo = cinfo;
    table.ApplyLogOnInfo(table.LogOnInfo);
}
string[] docnumbers=new[]{"1","2","3","4"};

for(int i=0;i<docnumbers.Lenght; i++)
{
    report.SetParameterValue(0, docnumbers[i]);
    report.Refresh();
    DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
    PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
    CrDiskFileDestinationOptions.DiskFileName = "C:\\generatedpdf " + docnumbers[i] + ".pdf";
    ExportOptions CrExportOptions = reportDoc.ExportOptions;
    {
        CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
        CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
        CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
        CrExportOptions.FormatOptions = CrFormatTypeOptions;
    }
    reportDoc.Export();
}
reportDoc.Close();
Was it helpful?

Solution

The problem was at report.Refresh(); when i removed that line it worked...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top