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


 reportViewer1.Visible = true;

 ReportDataSource rds = new ReportDataSource();


 reportViewer1.ProcessingMode = ProcessingMode.Local;

 LocalReport rep = reportViewer1.LocalReport;


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


4 Responses to “Adding Report Datasource On Runtime to a rdlc file on ReportViewer”

  1. Arun M November 28, 2012 at 11:21 am #

    Thank u mr nithesh, this is very helpful to me thank u

    • nithuan November 28, 2012 at 11:32 am #

      @Thx arun. happy to help you 🙂

  2. Anonymous September 25, 2013 at 2:35 pm #

    Thanks Nitesh, it`s wonderful demo, I found one more helpful demo i.e.


  1. Automaticaly Printing RDLC in Asp.Net MVC 3 | TECH-ELITE - March 29, 2013

    […]             The following code is for dynamically setting the data source to rdlc. I already wrote about this here […]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: