Click here to Skip to main content
Licence 
First Posted 21 Mar 2003
Views 447,319
Bookmarked 80 times

Crystal Reports PUSH method using ASP.NET

By | 21 Mar 2003 | Article
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:

    protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;
  7. Populate the DataSet. Set the report DataSource and CrystalReportViewer report source.
    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

About the Author

Omkar Bhave M

Software Developer (Senior)
Autodesk Inc.
United States United States

Member

my name is omkar bhave. I work in Autodesk Inc. USA.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionAwesome! Pinmemberchriskellerx104:26 30 Mar '12  
GeneralMy vote of 3 Pinmemberjyothi87.u4:44 28 Sep '11  
GeneralProblem loading report wid dataset PinmemberMember 449102723:15 30 Mar '11  
QuestionHow to use an external dataset Pinmemberarvee20035:05 14 Feb '11  
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 Pinmembermagham12:36 14 Dec '10  
GeneralMy vote of 5 Pinmembermagham12:33 14 Dec '10  
Generali added a crystal report to my window application.. but when i try create an object i cant access it Pinmemberpooran singh niranjan1:47 28 Jun '10  
GeneralMessage Removed PinmemberJAYRAJ GIRI0:52 7 Dec '09  
GeneralRe: Crytal reports PinmemberKhanImranKhan19:56 26 Jan '10  
Generalerror in this line CrystalReport1 report=new CrystalReport1(); PinmemberMember 39714689:40 16 Apr '09  
GeneralRe: error in this line CrystalReport1 report=new CrystalReport1(); PinmemberVejeeSachi15:36 26 Apr '09  
GeneralRe: error in this line CrystalReport1 report=new CrystalReport1(); Pinmemberashish64198621:40 19 May '09  
GeneralRe: error in this line CrystalReport1 report=new CrystalReport1(); Pinmemberwbeetge21:16 23 Feb '10  
GeneralRe: error in this line CrystalReport1 report=new CrystalReport1(); PinmemberMember 449102723:24 30 Mar '11  
GeneralMY ID [modified] PinmemberJAYRAJ GIRI3:04 11 Apr '09  
Generalcrystal reports PinmemberJAYRAJ GIRI20:59 26 Mar '09  
GeneralDynamically alter the page size of crystal report Pinmemberdilip51421:10 11 Mar '09  
QuestionDataset with multiple tables PinmemberSpunkybabe5:53 23 Feb '09  
QuestionSet Formula field in Crystal report Pinmemberbiswajit nayak22:52 15 Nov '08  
GeneralCrystal report PinmemberAmit S Manekar23:06 2 Oct '08  
i added a crystal report to my asp.net.. but when i try create an object i cant access it
 
i want to say: CrystalReport objRpt = new CrystalReport ();
But i cant do this..
 
ended up using this code:
 
ReportDocument rpt = new ReportDocument();
string reportPath = Server.MapPath("CrystalReport .rpt");
rpt.Load(reportPath);
rpt.SetDataSource(ds);
CrystalReportViewer.ReportSource = rpt;
CrystalReportViewer.DataBind();
CrystalReportViewer.Visible = true;
CrystalReportViewer.HasExportButton=true;
 
please help me.
Generalcant access the crystalReport PinmemberSlick6911:27 4 Sep '08  
QuestionHow to Connect Crystal Report with SQL Server 2000 in VB.Net/ Pinmemberemrugesh6:37 18 Aug '08  
QuestionCan anyone tell me how to upload ASP.NET application with Crystal report on WEB PinmemberAmit Papriwal22:14 10 Jul '08  
QuestionCrystal Report in asp.net 2005 Facing Problem PinmemberGIRISH KUMAR PRAJAPATI19:30 9 Jun '08  
QuestionHow to set a fixed height of Crystal report in asp.net PinmemberJhanvy Thaker21:53 7 May '08  

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.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120529.1 | Last Updated 22 Mar 2003
Article Copyright 2003 by Omkar Bhave M
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid