The following is my Employee Table, of which the data I will show as a report in ASP.NET using Crystal Reports.
Image 1.
Now open Visual Studio then select File -> New -> Web Site.
Image 2.
Then right-click on the Solution Explorer then select Add New Item then select Crystal Reports then click Add.
Image 3.
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.
Image 5.
Now enter your SQL Server details.
Image 6.
Image 7.
Now select your database then select your table and Move.
Image 8.
Now select the columns to be shown in the reports. Then click Finish.
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.
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:- using System;
- using System.Configuration;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Xml.Linq;
- using CrystalDecisions.CrystalReports.Engine;
-
- public partial class _Default : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- ReportDocument cryRpt = new ReportDocument();
- cryRpt.Load(Server.MapPath("EmployeeCrystalReport.rpt"));
- CrystalReportViewer1.ReportSource = cryRpt;
- }
- }
Now run your application:
Image 12.
No comments:
Post a Comment