Archive | Reporting Services RSS feed for this section

Adding Report Datasource On Runtime to a rdlc file on ReportViewer

27 Jul

While using client report definition (rdlc) for reporting in a .net application we need to create a dataset for its datatsource. It may cause a problem of diiferent connections for each report are there in a single application . For avoiding  this we can dynamically set datasource for report during run time.

1.      For this first we need to add the rdlc File

2.Add a Dataset for designing the report

3.Add a table adapte r with corresponding stored procedure or query.

4. After creating the data adapter we can access this in our report definition(rdlc)

5. Design the rdlc file using this dataset. After designing remove tha dataset from the project.

We can dynamicaaly assign the datasource from our bussiness logic at runtime to the rdlc file. For this e need to add  MicrosoftReportViwer into our form.

.

Here we can  set the datasource to the rdlc file using the following code.

 BLL.Class obj= new BLL.Class();

 DataTable dtTest = obj.SelectData();

 this.reportViewer1.RefreshReport();

 reportViewer1.Visible = true;

 ReportDataSource rds = new ReportDataSource();

 reportViewer1.Reset();

 reportViewer1.ProcessingMode = ProcessingMode.Local;

 LocalReport rep = reportViewer1.LocalReport;

 rep.Refresh();

 rep.ReportEmbeddedResource =“Report1.rdlc”;

 rds.Name = “DataSet1_Data”

reportViewer1.RefreshReport();

reportViewer1 : Name of the MicrosoftReportViwer control

We can also pass report parameters to rdlc as follows

//Report parameter,

ReportParameter rp = new ReportParameter(“content”,”HELLO”);//(Param name,value)

this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { rp });