Click here to Skip to main content
15,884,425 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 561K   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

 
GeneralGood article Pin
fixerfrasse20-Sep-04 7:51
fixerfrasse20-Sep-04 7:51 
GeneralAll pages in one asp.net Pin
Manish P9-Sep-04 23:11
Manish P9-Sep-04 23:11 
GeneralCrystal Reports: DatasourceException Pin
spn24-Aug-04 0:46
spn24-Aug-04 0:46 
GeneralDisplaying images in Crystal report. Pin
sansav12-Aug-04 23:14
sansav12-Aug-04 23:14 
GeneralUsing more than one datasource. Pin
sansav12-Aug-04 22:39
sansav12-Aug-04 22:39 
Questionincorrect log on parameters - problem? Pin
Member 72717316-Jun-04 10:50
Member 72717316-Jun-04 10:50 
AnswerRe: incorrect log on parameters - problem? Pin
Víctor Sánchez30-Aug-04 23:02
Víctor Sánchez30-Aug-04 23:02 
GeneralReading Ahead Pin
Anonymous20-May-04 9:40
Anonymous20-May-04 9:40 
GeneralRe: Reading Ahead Pin
Anonymous20-May-04 10:30
Anonymous20-May-04 10:30 
GeneralPrinting Reports (ASP.net) Pin
Sarvesvara (BVKS) Dasa28-Mar-04 19:15
Sarvesvara (BVKS) Dasa28-Mar-04 19:15 
GeneralRe: Printing Reports (ASP.net) Pin
sansav12-Aug-04 23:25
sansav12-Aug-04 23:25 
GeneralRe: Printing Reports (ASP.net) Pin
sd_hartono4-Sep-04 22:23
sd_hartono4-Sep-04 22:23 
GeneralRe: Printing Reports (ASP.net) Pin
Anonymous7-Sep-04 19:07
Anonymous7-Sep-04 19:07 
GeneralRe: Printing Reports (ASP.net) Pin
Anonymous21-Dec-04 20:23
Anonymous21-Dec-04 20:23 
GeneralPUSH in runtime Pin
Håkan Nilsson (k)2-Mar-04 23:23
Håkan Nilsson (k)2-Mar-04 23:23 
QuestionHow can I push a image column into Crystal Reports with PUSH method?? Pin
Goldsunline26-Feb-04 14:40
Goldsunline26-Feb-04 14:40 
Generalproblem using mysql database in the push method Pin
saira N19-Feb-04 11:18
saira N19-Feb-04 11:18 
Generaldoubts Pin
Sarvesvara (BVKS) Dasa26-Jan-04 2:30
Sarvesvara (BVKS) Dasa26-Jan-04 2:30 
GeneralRe: doubts - a next level Pin
Sarvesvara (BVKS) Dasa26-Jan-04 2:57
Sarvesvara (BVKS) Dasa26-Jan-04 2:57 
GeneralRe: doubts - still NOT ok Pin
Sarvesvara (BVKS) Dasa26-Jan-04 3:27
Sarvesvara (BVKS) Dasa26-Jan-04 3:27 
QuestionHow can i disapear the Powereb By Crystal Logo Pin
Haaron Gonzalez21-Jan-04 8:07
Haaron Gonzalez21-Jan-04 8:07 
AnswerRe: How can i disapear the Powereb By Crystal Logo Pin
Sarvesvara (BVKS) Dasa27-Jan-04 21:17
Sarvesvara (BVKS) Dasa27-Jan-04 21:17 
GeneralRe: How can i disapear the Powereb By Crystal Logo Pin
Malieka15-Apr-04 12:12
Malieka15-Apr-04 12:12 
GeneralRe: How can i disapear the Powereb By Crystal Logo Pin
Víctor Sánchez30-Aug-04 23:13
Víctor Sánchez30-Aug-04 23:13 
AnswerRe: How can i disapear the Powereb By Crystal Logo Pin
thuantd15-Nov-04 15:44
thuantd15-Nov-04 15:44 

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.