Wednesday, February 24, 2010

Crystal Report With Asp.NET – Data Set in Different Project

When architecting the system some types you might layering the application to Data Layer and Presentation Layer. Therefore you normally put the Dataset to the data layer, But your report in the presentation layer. Thus When you are creating the crystal report in Presentation Layer it is not showing the Data Set which is in the Data Layer.

image 

There fore when you are creating the report using data set, it is shown as empty.

image   Thus you want to copy the dataset to the project. For that copy and paste the data set to the project.

image

Now you can design your report by adding the dataset as previous article. After design the report you can delete the dataset i the project (WebApplication)

Now we want to call the report when the page is loading.

Report.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{

ReportDocument CollReport = new ReportDocument();
string reportPath = Server.MapPath("CrystalReport.rpt");
CollReport.Load(reportPath);

DataLayer.DataSetTableAdapters.Table1TableAdapter ta =
new DataLayer.DataSetTableAdapters.Table1TableAdapter();
// We have to refere Datalayer project

DataLayer.DataSet.Table1DataTable dt =
new DataLayer.DataSet.Table1DataTable();

ta.Fill(dt);

CollReport.SetDataSource((DataTable)dt);
CrystalReportViewer1.ReportSource = CollReport;
}
Post a Comment