Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Creating a simple but useful Crystal Report

0.00/5 (No votes)
28 Nov 2012 1  
Crystal Reports for beginners.

What is Crystal Reports?

Crystal Reports is a database reporting application. It has powerful capabilities to access and analyze various sources of data for its reports.

Note: Please do comment for suggestions and improvements for me to update my first tip/trick entry. Thanks!

Steps in Making Crystal Report

First, you need to download the complete package in:

*VS = Visual Studio

For VS2010: http://scn.sap.com/docs/DOC-7824

For VS2008: http://scn.sap.com/docs/DOC-27917

After Download and Install. 

  1. Create a new project.
  2. Add a CrystalReportViewer to your WebForm.

Select the project name and then perform the following:

  1. Add New Item
  2. Select Report and then select Crystal Reports
  3. Save your File as "StudentList.rpt"

Just close the dialog box that appear or select Blank Report

A Blank report will be created.

Now, select the project name and then perform the following:

  1. Add New Item
  2. Select DataSet
  3. Save your DataSet as "StudentRec.xsd"
  4. Drag a table from your Sever Explorer going to your DataSet designer.

Go back to CrystalReport.rpt.

Create a class Library and named it as "ReportHelper" and then rename the Class as "DataReport" and then write the following code below:

Note: This is the code when you are using a DataSet.

using System.text;
using System.Data;
using System.Data.SqlClient;

namespace ReportHelper
{
    public class DataReport
    {
       private static string _connString = @"Data Source";
        public static DataSet LoadReport()
        {
            SqlConnection myConn = new SqlConnection(_connString);
            SqlDataAdapter da = new SqlDataAdapter("Select * from StudentRecord", myConn);
            DataSet ds = new DataSet();
            da.Fill(ds, "StudTable");
            return ds;
        }
    }
}

On Page_Load event write the following code and then run your application.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ReportHelper;
using System.Data;
using System.Data.SqlClient;

namespace CrystalReport
{

    public partial class WebForm1 : System.Web.UI.Page    {
        protected void Page_Load(object sender, EventArgs e)
        {
            DataView dview = new DataView();
            dview.Table = DataReport.LoadReport().Tables["StudTable"];

            StudentList myreport = new StudentList();
            myreport.SetDataSource(dview)
            CrystalReportViewer1.ReportSource = myreport;
            CrystalReportViewer1.DataBind();
        }
    }
}

I hope that this Tip may help you to understand and create a simple but useful Crystal Report.

Thank you for reading my tip.

-Jason P.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here