The following Crystal Report class libraries are introduced into the project
Crystaldecisions.crystalreports.engine
Crystaldecisions.reportsource
Crystaldecisions.shared
Crystaldecisions.web
Add the Crystalreportviewer control to the page. Add code for his initialization at the same time
System.Data.DataTable dt = ....//The method by which the data table is written. Can write according to their own hobbies, but must get
DataTable
CrystalReport1 cr = new CrystalReport1 ();//The CrystalReport1 here is the file name that you set up the report is the RPT name.
Cr. Setdatasource (DT);
This. Crystalreportviewer1.reportsource = CR;
If you want to export the file, the code is as follows
private void Button1_Click (object sender, System.EventArgs e)
{
System.Data.DataTable dt = ....;
CrystalReport1 cr = new CrystalReport1 ();
Cr. Setdatasource (DT);
Cr. Exporttodisk (CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, "c:\\output.pdf");
Cr. Close ();
}
Where CrystalDecisions.Shared.ExportFormatType.PortableDocFormat can control the type of output file
Crystal Report output PDF file in C #