Search Chirayu Software Solutions Blog

Thursday, October 11, 2012

Crystal Report Session -1

Step-1 : Download Crystal Report from below link

Step -2 Create new website

Step - 3 Create Database and One employee table with some filed and data

Step -4 Create Dataset for a employee table

Step -5 Add Crystal Report


Now it will ask for the reportcreation type of how you want to create the report.

Just click ok button to proceed

Step- 6 Click Project Data >ADO.NET Datasets
Now clik >> button  on dataset


Now click on the Finish button and it will show the next screen


Once report file is added, you can see Field Explorer on the left side near server explorer.
Expand Database Fields, under that you will be able to find Datatable that we have created earlier. Just expand it and drag one by one filed from Field Explorer to the rpt file under detail section.

Now the report design part is over. Now we have to fetch the data from d dataset and then bind that  to the report viewer.

Step -7
First Drag a CrystalReportViewer control on aspx page from tool box as per below screen:


Step -8 Now Add following code in .cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

public partial class ReportViewer : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        ReportDocument rptDoc = new ReportDocument();

// First Three line of using Dataset
        DataSet1TableAdapters.infoTableAdapter da= new DataSet1TableAdapters.infoTableAdapter();
        DataSet1.infoDataTable dt1 = new DataSet1.infoDataTable();
        DataSet1.infoRow dr1;
     // Fetch Data
        dt1 = da.GetData();

        // Your .rpt file path will be below

        //set dataset to the report viewer.
             CrystalReportViewer1.ReportSource = rptDoc;

Now just save everything and run report.

No comments: