Click here to Skip to main content
15,885,366 members
Articles / Web Development / ASP.NET
Tip/Trick

Creating a simple but useful Crystal Report

Rate me:
Please Sign up or sign in to vote.
4.58/5 (10 votes)
28 Nov 2012CPOL1 min read 133.9K   14   8
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.

Image 1

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

Image 2

A Blank report will be created.

Image 3

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.

Image 4

Go back to CrystalReport.rpt.

Image 5

Image 6

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.

C#
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.

C#
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Philippines Philippines
Web Addict.
Focused on PHP Programming.
Back - End.

Comments and Discussions

 
QuestionSteps missing Pin
Member 1148523327-Feb-15 3:25
Member 1148523327-Feb-15 3:25 
QuestionNeed stored procedure for this crystal report Pin
dino04143-Jul-14 1:09
dino04143-Jul-14 1:09 
GeneralVery Nice Post Pin
dino04142-Jul-14 21:38
dino04142-Jul-14 21:38 
QuestionError Pin
Member 1076309720-Apr-14 21:10
Member 1076309720-Apr-14 21:10 
GeneralMissing Images Pin
Tim Corey27-Nov-12 2:41
professionalTim Corey27-Nov-12 2:41 
GeneralRe: Missing Images Pin
esonparedes27-Nov-12 13:17
esonparedes27-Nov-12 13:17 
QuestionNot an article.. Pin
Monjurul Habib26-Nov-12 18:46
professionalMonjurul Habib26-Nov-12 18:46 
AnswerRe: Not an article.. Pin
esonparedes26-Nov-12 18:57
esonparedes26-Nov-12 18:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.