cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal Report

Former Member
0 Kudos

Dear Experts,

I have a crystal report that requires some parameters. and after giving the parameters it populates the data as per the parameters. Now I want that these parameters should be passed by code and after that this report should be exported into PDF Format.

Is that possible to do ?

Plz help.

Regards

Accepted Solutions (1)

Accepted Solutions (1)

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

Here is a sample how to do it:

ReportDocument cryRpt = new ReportDocument();

string path = System.Windows.Forms.Application.StartupPath + @"\Customer Statement.rpt";

cryRpt.Load(path);

cryRpt.SetDatabaseLogon(ConfigurationSettings.AppSettings["sqluname"], ConfigurationSettings.AppSettings["sqlpass"], ConfigurationSettings.AppSettings["sqlserver"], ConfigurationSettings.AppSettings["dbname"], false);

cryRpt.SetParameterValue("CardCode@Select * from OCRD where Cardtype = 'C'", "C0015");

string FromDate = "20150103";

SAPbobsCOM.SBObob objBridge = (SAPbobsCOM.SBObob)SBO_Company.GetBusinessObject(BoObjectTypes.BoBridge);

string ValidFromDate = FromDate;

DateTime FromDt = Convert.ToDateTime(objBridge.Format_StringToDate(ValidFromDate).Fields.Item(0).Value);

string ToDate = "20150430";

string ValidToDate = ToDate;

DateTime ToDt = Convert.ToDateTime(objBridge.Format_StringToDate(ValidToDate).Fields.Item(0).Value);

          

cryRpt.SetParameterValue("fromdate", FromDt);

          

cryRpt.SetParameterValue("Todate@", ToDt);

          

ExportOptions CrExportOptions;

          

DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();

          

PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();

          

CrDiskFileDestinationOptions.DiskFileName = System.Windows.Forms.Application.StartupPath + @"\Mail" + "25" + ".pdf";

          

CrExportOptions = cryRpt.ExportOptions;

          

{

              

CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;

              

CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

              

CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;

              

CrExportOptions.FormatOptions = CrFormatTypeOptions;

          

}

          

cryRpt.Export();

Hope it helps.

Thanks & Regards

Ankit Chauhan

Former Member
0 Kudos

Hi,

I will check it and reply.

Regards

Former Member
0 Kudos

Hi,

How to set the parameter in your code ?

Regards

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi,

cryRpt.SetParameterValue("fromdate", FromDt);

         

cryRpt.SetParameterValue("Todate@", ToDt);

These lines are setting the parameter field in the code. What you need to do is that open your Crystal Report and select the Parameter Field. Now right click on it and select Edit. And use the exact name for the parameter.

Hope it helps.

Thanks & Regards

Ankit Chauhan

Former Member
0 Kudos

Hi,

Thanks... Problem solved.

Regards

Answers (1)

Answers (1)

ANKIT_CHAUHAN
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Kuldeep,

Your requirement is very much possible. First you need to use references

CrystalDecisions.CrystalReports.Engine & CrystalDecisions.Shared.

Then using ReportDocument and ExportOptions you can achieve what you need.

Hope it helps.

Thanks & Regards

Ankit Chauhan