Click here to Skip to main content
15,867,453 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

 
Questionplease help Pin
muthumani12-Feb-08 0:02
muthumani12-Feb-08 0:02 
QuestionASP to crystal Reports .rpt NEED HELP Pin
mjelin26-Apr-07 9:10
mjelin26-Apr-07 9:10 
GeneralQuestion adout PUSH model Pin
Derrick Lasantha11-Mar-07 23:41
Derrick Lasantha11-Mar-07 23:41 
QuestionQuestion Pin
iceborg24-Jan-07 4:03
iceborg24-Jan-07 4:03 
AnswerRe: Question Pin
Omkar Bhave M24-Jan-07 11:16
Omkar Bhave M24-Jan-07 11:16 
Questionicons missing when report is run Pin
techie_risa8-Jan-07 19:39
techie_risa8-Jan-07 19:39 
AnswerRe: icons missing when report is run Pin
Sylvester george24-Jan-07 4:17
Sylvester george24-Jan-07 4:17 
AnswerRe: icons missing when report is run Pin
prabodhbansal5-Feb-07 1:07
prabodhbansal5-Feb-07 1:07 
GeneralHelp , asp.net 1.0 with crystal report Pin
beginhs11-Oct-06 16:58
beginhs11-Oct-06 16:58 
QuestionCannot get specific Line of code Pin
Gaurav Rathod17-Jul-06 20:34
Gaurav Rathod17-Jul-06 20:34 
GeneralHELP Pin
malemsteen2-Jul-06 0:00
malemsteen2-Jul-06 0:00 
GeneralLogon Problem Pin
Muneeeb13-Apr-06 21:00
Muneeeb13-Apr-06 21:00 
GeneralKeyup in datagrid in vb.net Pin
Anonymous6-Aug-05 0:48
Anonymous6-Aug-05 0:48 
GeneralCrystal report In asp.net Pin
Anonymous6-Aug-05 0:40
Anonymous6-Aug-05 0:40 
GeneralPage Scrolling in Crystal Reports 11 .NET Pin
babukabraham@yahoo.com13-Jun-05 5:00
sussbabukabraham@yahoo.com13-Jun-05 5:00 
GeneralCreating Report Dynamically Pin
10-Apr-05 22:34
suss10-Apr-05 22:34 
GeneralGood Article Pin
NormDroid6-Apr-05 4:33
professionalNormDroid6-Apr-05 4:33 
GeneralPlugging report with Dataset Pin
Anonymous2-Mar-05 11:14
Anonymous2-Mar-05 11:14 
GeneralCrystal Report in .Net Pin
GeethP1-Mar-05 21:58
GeethP1-Mar-05 21:58 
QuestionHow justify report? Pin
myanonym23-Feb-05 8:50
myanonym23-Feb-05 8:50 
AnswerRe: How justify report? Pin
Anonymous21-Sep-05 14:44
Anonymous21-Sep-05 14:44 
Generalcrystal report sample Pin
Anonymous25-Nov-04 19:48
Anonymous25-Nov-04 19:48 
GeneralManually code the dataset and report bind Pin
cfaulkner1-Nov-04 5:45
cfaulkner1-Nov-04 5:45 
GeneralRe: Manually code the dataset and report bind Pin
fixerfrasse14-Nov-04 18:10
fixerfrasse14-Nov-04 18:10 
QuestionIf the report having a sub report, how can I do? Pin
Goldsunline5-Oct-04 20:10
Goldsunline5-Oct-04 20:10 

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.