Monday, May 16, 2011

Creating crystal report with custom datasource datatable

We can use datatable as cutom datasource to crystal report with the following steps.
A.add dataset and datatable as below
-right click the project and add dataset


-double click the datatable in dataset toolbox
-right click the new datatable and add columns



B Add crystal report template
and follow the report wizard





on the list of available data sources,under the node project data and ado.net datasets,there is dataset1 which is to be selected.Move it to selected tables


add available fields to fields to display





add crystal report viewer to a form where report is to be displayed and
add following code to the form load.


Dataset1 ds = new Dataset1 ();
ds.Tables.Add(dt);
CRTransaction objRpt = new CRTransaction();
objRpt.SetDataSource(ds.Tables[1]);
crystalReportViewer1.ReportSource = objRpt;
crystalReportViewer1.Refresh();

dt is can be datasource of gridview or any custom datatable.


No comments:

Post a Comment