Crystal Reports PUSH method using ASP.NET






3.61/5 (55 votes)
Mar 22, 2003
2 min read

569549
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 DataSet
s in an ASP.NET page for reports. There are two types of methods for drawing the reports:
PULL
method- the crystal report makes connection with the database, brings the fields data and draws the report.PUSH
method- we create theDataSet
, choose fields of theDataSet
as report fields and then push it to the crystal report. Here I am going to explain thePUSH
method only.
Steps
- Create a new ASP.NET project.
- Insert new item as
DataSet
. - Add elements to the
DataSet
which you want on the report. Save All, then right click on theDataSet
filename in the solution explorer and select command "Build and browse". - Then add a new item to the project as “Crystal report” and insert a blank report.
- 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. - 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;
- Populate the
DataSet
. Set the reportDataSource
andCrystalReportViewer
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...
Points to be careful of
- Give same names on
Dataset
and the table element name of insertedDataSet
. - As and when you modify
DataSet
, build it again and log off the current connections in report. Set theDataSource
location again pointing to newDataSet
, otherwise database fields of the report will not take the change. - Setting up
DataBind
properties of the report viewer can be avoided. It can be done at runtime.