Sunday 8 May 2011

Crystal Report in C#

Crystal Report
Crystal Report is used to generate the report of database for taking preview and printout of that particular data or report. Add crystal in your application by choosing new item you will get new window like below and select reporting => then crystal report.


You can customize report according to your choice by the use of CrystalReport toolbox. Choose database from field explorer window as shown below-






Now add fields in your report those you want to show in your report as shown below.


Drag and drop crystal report viewer from toolbox and set property that you want to customize your CrystalReport.




                                                                                       
Code for to show crystal report Form- write following code on View CrystalReport Button. 

private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Crystal c = new Crystal();
            c.ShowDialog();
        }

Code for calling CrystalReport- Write following code on CrystalReport Page load event.

 private void Crystal_Load(object sender, EventArgs e)
        {
            CrystalReport1 cryRpt = new CrystalReport1();
            cryRpt = new CrystalReport1();
            cryRpt.Load("\\preview_invoice_report.rpt");
            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh();
        }
 Report will generate as shown below-

No comments:

Post a Comment