Dynamically setting the Report Data source for rdlc in Report viewer

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. To begin with we need to add a new rdlc file into the project.
Add a new rdlc file

2. Then add a Dataset for designing the report

Add a dataset

3. To populate the dataset add a table adapter with corresponding stored procedure or a query to fetch the data.


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

5. Once the data set s added, design the report(rdlc) based on your using this dataset . After designing remove this dataset from the project.

6. We need to add  MicrosoftReportViwer into our form/aspx page .

7. Then we can dynamically assign the data source from the data access or business logic in the code as detailed below.

 BLL.Class obj= new BLL.Class();
 // Getting the data 
 DataTable dtTest = obj.SelectData();

 reportViewer1.ProcessingMode = ProcessingMode.Local;
 LocalReport rep = reportViewer1.LocalReport;
 ReportDataSource rds = new ReportDataSource(dtTest);
 rep.ReportEmbeddedResource ="Report1.rdlc";
 rds.Name = "DataSet1_Data";

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 });

One Reply to “Dynamically setting the Report Data source for rdlc in Report viewer”

  1. Its like you learn my thoughts! You seem to understand a lot approximately this, such as you wrote the e-book in it or something. I believe that you can do with some to power the message house a little bit, but other than that, this is fantastic blog. A great read. I’ll definitely be back.

Leave a Reply

Your email address will not be published. Required fields are marked *