0
votes

Does anyone know how to use multiple .rpt files (crystal reports) in one application? I need to generate reports and directly save to .pdf but I'm not sure how to do it. I manage to do it when I’m using single .rpt file but I’m not sure how to generate report with multiple .rpt file. Can someone assist me with thid?

My coding:

ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;

cryRpt.Load("C:\\rptBilling.rpt");

crConnectionInfo.ServerName = "ServerName";
crConnectionInfo.DatabaseName = "DatabaseName";
crConnectionInfo.UserID = "userID";
crConnectionInfo.Password = "Password";

CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
    crtableLogoninfo = CrTable.LogOnInfo;
    crtableLogoninfo.ConnectionInfo = crConnectionInfo;
    CrTable.ApplyLogOnInfo(crtableLogoninfo);
}

cryRpt.SetParameterValue("@CollectionStartDate", "2011/09/14");
cryRpt.SetParameterValue("@CollectionEndDate", "2011/09/29");
cryRpt.SetParameterValue("@SpokeCode", "14");//country code
cryRpt.SetParameterValue("@UseCollectionDate", "1");//value can be set 0 or 1
cryRpt.SetParameterValue("@UseUploadDate", "0");//value can be set 0 or 1
cryRpt.SetParameterValue("@UploadStartDate", "2011/09/23");
cryRpt.SetParameterValue("@UploadEndDate", "2011/09/23");

cryRpt.ExportToDisk(ExportFormatType.PortableDocFormat, "e:\\1.pdf");
1

1 Answers

0
votes

If you mean separate pdf files, then you could just reload the new rpt using cryRpt.Load(). Make sure you clear your parameters and SetParameterValue on new ones.

Edit: I can't make comments as I don't have enough points for that but I've never used the Crystal Reporting feature but I'm assuming you can keep the same variable cryRpt and once you load your first pdf you could reuse cryRpt by calling Load() again and going through the same steps as you did already but using new variables if needed. If it doesn't allow multiple cryRpts you could just dispose and initialize a new one. I could be misunderstanding what you are looking for as I am assuming you want two separate pdf files.