Thursday, 17 March 2011

attaching a report at runtime to report document in asp.net

You can attach a crystal report at the run time to a report viewer.

To attach a report to the report viewer at the run time follow the following steps:

Create the object of report document :

ReportDocument rpt=new ReportDocument();

Load the report it is assumed that the report reside of the root of the application:

rpt.Load(HttpContext.Current.Server.MapPath("abc.rpt"));

Set the data source of the report document :

rpt.SetDataSource(ds.Tables[0]);

Provide the value of the prameter if report contain any parameter

rpt.SetParameterValue("pName", "abc");


Set the report source of the report viewer to the report source.