Click here to Skip to main content
15,867,291 members
Articles / Web Development / ASP.NET
Article

Crystal Reports PUSH method using ASP.NET

Rate me:
Please Sign up or sign in to vote.
3.61/5 (55 votes)
21 Mar 20032 min read 559.3K   80   77
This article explains how to use PUSH method for drawing reports.

Introduction

This article explains how to use PUSH method for drawing reports. It will also explain how to use user DataSets in an ASP.NET page for reports. There are two types of methods for drawing the reports:

  1. PULL method- the crystal report makes connection with the database, brings the fields data and draws the report.
  2. PUSH method- we create the DataSet, choose fields of the DataSet as report fields and then push it to the crystal report. Here I am going to explain the PUSH method only.

Steps

  1. Create a new ASP.NET project.

    Sample screenshot

  2. Insert new item as DataSet.

    Sample screenshot

  3. Add elements to the DataSet which you want on the report. Save All, then right click on the DataSet filename in the solution explorer and select command "Build and browse".
  4. Then add a new item to the project as “Crystal report” and insert a blank report.
  5. In the server explorer, right click database field and select database expert and expand the project data and select DataSet in the table selector and press OK.

    Sample screenshot

  6. Then drag the fields from the database fields of server explorer in the detail section of the report. Arrange the fields as you want.

    From the toolbox, add crystal report viewer control on to the page. That will add this variable:

    C#
    protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;
  7. Populate the DataSet. Set the report DataSource and CrystalReportViewer report source.
    C#
    private void Page_Load(object sender, System.EventArgs e)
    {
    CrystalReport1 report=new CrystalReport1();
    CrystalReportViewer1.Visible=true;
    DataSet ds=new DataSet("Account");//give same name as on 
    //dataset1 table header
    DataTable table=new DataTable("Account");//give same name as on 
    //dataset1 table header 
    table.Columns.Add("Fname",typeof(System.String));
    table.Columns.Add("Lname",typeof(System.String));
    table.Columns.Add("Salary",typeof(System.String)); 
    DataRow row=table.NewRow();
    row["Fname"]="Mathew";
    row["Lname"]="Hayden";
    row["Salary"]="5000$";
    // add to table
    table.Rows.Add(row);
    ds.Tables.Add(table);
    // set report's dataset
    report.SetDataSource(ds);
    // set report source
    CrystalReportViewer1.ReportSource =report;
    }

    The output will be as follows...

    Sample screenshot

Points to be careful of

  1. Give same names on Dataset and the table element name of inserted DataSet.
  2. As and when you modify DataSet, build it again and log off the current connections in report. Set the DataSource location again pointing to new DataSet, otherwise database fields of the report will not take the change.
  3. Setting up DataBind properties of the report viewer can be avoided. It can be done at runtime.

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


Written By
Software Developer (Senior) Autodesk Inc.
United States United States
my name is omkar bhave. I work in Autodesk Inc. USA.

Comments and Discussions

 
QuestionReport with detail Pin
Zeeshan-Ali8922-Jul-12 20:17
Zeeshan-Ali8922-Jul-12 20:17 
QuestionAwesome! Pin
chriskellerx1030-Mar-12 4:26
chriskellerx1030-Mar-12 4:26 
GeneralMy vote of 3 Pin
jyothi87.u28-Sep-11 4:44
jyothi87.u28-Sep-11 4:44 
GeneralProblem loading report wid dataset Pin
Member 449102730-Mar-11 23:15
Member 449102730-Mar-11 23:15 
QuestionHow to use an external dataset Pin
arvee200314-Feb-11 5:05
arvee200314-Feb-11 5:05 
GeneralCould you please send the project code , I am facing some issue in creating reports object as I am unable to create a New web project in VS2005 Pin
magham14-Dec-10 12:36
magham14-Dec-10 12:36 
GeneralMy vote of 5 Pin
magham14-Dec-10 12:33
magham14-Dec-10 12:33 
Generali added a crystal report to my window application.. but when i try create an object i cant access it Pin
pooran singh niranjan28-Jun-10 1:47
pooran singh niranjan28-Jun-10 1:47 
GeneralRe: Crytal reports Pin
KhanImranKhan26-Jan-10 19:56
KhanImranKhan26-Jan-10 19:56 
Generalerror in this line CrystalReport1 report=new CrystalReport1(); Pin
Ricardo_Torres_Torres16-Apr-09 9:40
professionalRicardo_Torres_Torres16-Apr-09 9:40 
GeneralRe: error in this line CrystalReport1 report=new CrystalReport1(); Pin
VejeeSachi26-Apr-09 15:36
VejeeSachi26-Apr-09 15:36 
GeneralRe: error in this line CrystalReport1 report=new CrystalReport1(); Pin
Ashish(HashCoder)19-May-09 21:40
Ashish(HashCoder)19-May-09 21:40 
GeneralRe: error in this line CrystalReport1 report=new CrystalReport1(); Pin
wbeetge23-Feb-10 21:16
wbeetge23-Feb-10 21:16 
Hi.

I am using VB and not C# for my project.
I am also trying to Display my XML file in Crystal report.

All examples are in c# and looks like this example.
When I change the code to VB syntax, I cannot see my report:

c# code:
CrystalReport1 report=new CrystalReport1();
vb code:
Dim oReport As New CrystalReport1 'produces error

I can see the created Dataset:

Dim dsReport As New dsPickList 'dsPicklist is in App_Code - works fine
Dim dsTempReport = New DataSet() 'works fine
Dim oReport As New CrystalReport1() 'Does not see my rpt file called CrystalReport1.rpt

dsTempReport.ReadXml("C:\PickList.xml") 'works fine
dsReport.Tables(0).Merge(dsTempReport.Tables(0)) ' seems to work

Now, oReport does not exist and I cannot apply the dataset to the report.
Can anyone help ? What am I missing ?
GeneralRe: error in this line CrystalReport1 report=new CrystalReport1(); Pin
Member 449102730-Mar-11 23:24
Member 449102730-Mar-11 23:24 
GeneralMY ID [modified] Pin
JAYRAJ GIRI11-Apr-09 3:04
JAYRAJ GIRI11-Apr-09 3:04 
Generalcrystal reports Pin
JAYRAJ GIRI26-Mar-09 20:59
JAYRAJ GIRI26-Mar-09 20:59 
GeneralDynamically alter the page size of crystal report Pin
dilip51411-Mar-09 21:10
dilip51411-Mar-09 21:10 
QuestionDataset with multiple tables Pin
Spunkybabe23-Feb-09 5:53
Spunkybabe23-Feb-09 5:53 
QuestionSet Formula field in Crystal report Pin
biswajit nayak15-Nov-08 22:52
biswajit nayak15-Nov-08 22:52 
GeneralCrystal report Pin
Amit S Manekar2-Oct-08 23:06
Amit S Manekar2-Oct-08 23:06 
Generalcant access the crystalReport Pin
Slick694-Sep-08 11:27
Slick694-Sep-08 11:27 
QuestionHow to Connect Crystal Report with SQL Server 2000 in VB.Net/ Pin
emrugesh18-Aug-08 6:37
emrugesh18-Aug-08 6:37 
QuestionCan anyone tell me how to upload ASP.NET application with Crystal report on WEB Pin
Amit Papriwal10-Jul-08 22:14
Amit Papriwal10-Jul-08 22:14 
QuestionCrystal Report in asp.net 2005 Facing Problem Pin
GIRISH KUMAR PRAJAPATI9-Jun-08 19:30
GIRISH KUMAR PRAJAPATI9-Jun-08 19:30 
QuestionHow to set a fixed height of Crystal report in asp.net Pin
Jhanvy Thaker7-May-08 21:53
Jhanvy Thaker7-May-08 21:53 

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.