Click here to Skip to main content
Click here to Skip to main content
Go to top

Creating a simple but useful Crystal Report

, 28 Nov 2012
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

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

Comments and Discussions

 
QuestionNeed stored procedure for this crystal report Pinmemberdino04143-Jul-14 1:09 
GeneralVery Nice Post Pinmemberdino04142-Jul-14 21:38 
Questiondownoad crystal report for the visual stdio 2014 PinmemberMember 101960382-Jun-14 7:33 
QuestionError PinmemberMember 1076309720-Apr-14 21:10 
GeneralMissing Images PinmemberTim Corey27-Nov-12 2:41 
GeneralRe: Missing Images Pinmemberesonparedes27-Nov-12 13:17 
QuestionNot an article.. PinmemberMonjurul Habib26-Nov-12 18:46 
AnswerRe: Not an article.. Pinmemberesonparedes26-Nov-12 18:57 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 28 Nov 2012
Article Copyright 2012 by esonparedes
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid