Create Crystal Reports Report in ASP.Net

The following is my Employee Table, of which the data I will show as a report in ASP.NET using Crystal Reports.
Employee Table
Image 1.
Now open Visual Studio then select File -> New -> Web Site.
New Web Site
Image 2.
Then right-click on the Solution Explorer then select Add New Item then select Crystal Reports then click Add.
Crystal Report
Image 3.
Crystal Report gallery
Image 4.
Here expand something then select Create New Connection then select OLE DB (ADO) then a pop-up window will open. Select Microsoft OLE DB Provider for SQL Server then click Next.
Microsoft OLE DB Provider
Image 5.
Now enter your SQL Server details.
SQL server Details.
Image 6.
local identifier
Image 7.
Now select your database then select your table and Move.
Select Your Table and Move
Image 8.
Now select the columns to be shown in the reports. Then click Finish.
Select those column
Image 9.
Now you can see your report is ready. All the columns are already in the Details sections. You can remove any column or you can add a new column by drag and drop from the fields explorer to the report.
field explorer to report
Image 10.
Now to add a Report Viewer for showing this Crystal Reports report. In the Default.aspx page drag and drop a CrystalReportViewer from the toolbox like the following.
Image 11.
Now for the Page_Load event write the following code:
  1. using System;  
  2. using System.Configuration;  
  3. using System.Data;  
  4. using System.Linq;  
  5. using System.Web;  
  6. using System.Web.Security;  
  7. using System.Web.UI;  
  8. using System.Web.UI.HtmlControls;  
  9. using System.Web.UI.WebControls;  
  10. using System.Web.UI.WebControls.WebParts;  
  11. using System.Xml.Linq;  
  12. using CrystalDecisions.CrystalReports.Engine;  
  14. public partial class _Default : System.Web.UI.Page  
  15. {  
  16.     protected void Page_Load(object sender, EventArgs e)  
  17.     {  
  18.         ReportDocument cryRpt = new ReportDocument();  
  19.         cryRpt.Load(Server.MapPath("EmployeeCrystalReport.rpt"));  
  20.         CrystalReportViewer1.ReportSource = cryRpt;           
  21.     }  
  22. }  
Now run your application:
Run your Application
Image 12.

Similar Articles