Load RDLC Report Using Report Viewer Programmatically

This tutorial will guide you on how to programmatically load the RDLC Report into Report Viewer Control.

I search the internet on how to do this but I can’t find one. There are answers in some forum site but the solution is not clear and don’t have a sample source code.

In my previous tutorial I discuss the solution for the error “The definition of the report 'Main Report' is invalid”. This time let’s talk about on how we can load the RDLC report programmatically using its own DataSet.

The source code I implemented here is very simple but it’s the best solution. Unlike with other samples on the internet, they use a lot of code to do a very simple task.

Here’s a sample of the code to display the RDLC Report programmatically.

Private Sub frmReport_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim rptDataSource As ReportDataSource Try With Me.ReportViewer1.LocalReport .ReportPath = "Reports\" & strReport & ".rdlc" .DataSources.Clear() End With Select strReport Case "Employees" Dim ds As New Load_RDLC_Report_Programmatically.EmployeesDataSet Dim da As New Load_RDLC_Report_Programmatically.EmployeesDataSetTableAdapters.EmployeesTableAdapter da.Fill(ds.Employees) ' Use the same name as defined in the report Data Source Definition rptDataSource = New ReportDataSource("EmployeesDataSet", ds.Tables("Employees")) Case "Customers" Dim ds As New Load_RDLC_Report_Programmatically.CustomersDataSet Dim da As New Load_RDLC_Report_Programmatically.CustomersDataSetTableAdapters.CustomersTableAdapter da.Fill(ds.Customers) ' Use the same name as defined in the report Data Source Definition rptDataSource = New ReportDataSource("CustomersDataSet", ds.Tables("Customers")) End Select Me.ReportViewer1.LocalReport.DataSources.Add(rptDataSource) Me.ReportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout) Catch ex As Exception MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub

Download the source code and try for yourself. Don’t hesitate to ask questions by leaving a message below.

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.


1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.


Submitted byAnonymous (not verified)on Sun, 09/11/2011 - 00:45

Please can you help me? I used SQL 2008 R2 for a file but if I try using data source to put it on a windows form application there is an error message I don't have permission to open the file. I am the only person using the computer. Please help. my email is [email protected]
Submitted byJ Boggess (not verified)on Mon, 05/21/2012 - 08:09

Thank you very much. This is a work around I needed for working in asp.net RDLC. It was easy to convert to C# asp.net web page.

Very useful! I've used in c# like this, with an store procedura that get the data, and loaded as a dataset.
  1. //property
  2. public string report;
  4. private void Form1_Load(object sender, EventArgs e)
  5. {
  6. var ds = new ImpresosDataSet();
  7. var reportDataSource = new ReportDataSource { Name = "ReportDataSet" };
  8. const string rut = "Reporting.Reports.";
  10. switch (report)
  11. {
  12. case "CustomerList":
  13. var da = new CustomerListTableAdapter();
  14. da.Fill(ds.CustomerList);
  15. reportDataSource.Value = da.GetData();
  16. break;
  17. //default:
  18. }
  20. reportViewer1.LocalReport.ReportEmbeddedResource = rut + report + ".rdlc";
  21. reportViewer1.LocalReport.DataSources.Clear();
  22. reportViewer1.LocalReport.DataSources.Add(reportDataSource);
  23. reportViewer1.RefreshReport();
  24. }
Submitted byAnonymous (not verified)on Mon, 06/24/2013 - 15:23

Good Day How can i load the data in reportViewer programmatically using MYSQL, VS 2010 and a ODBC 3.51 Connector..im stuck on the report.. please help
Submitted byAnonymous (not verified)on Thu, 06/27/2013 - 09:49

Hi Guys, I'm having hard time figuring how to use ReportViewer and report in MySQL programmatically(including dataset, datasource)..it seems that dBases is not physically visible unlike MS Access..can sum1 please help me with this..i'm new to VS2010..i upgraded from vb 6.0 and having hard time in report..
Submitted byAnonymous (not verified)on Tue, 07/16/2013 - 06:44

In line 15 is it appropriate to write da.Fill(ds.Employees,txtEmployeeID.text) to pass the parameter from the txtEmployeeID textbox. If not, then how can this be implemented Help a newbie thanks
Submitted byWindyD (not verified)on Sat, 07/27/2013 - 01:28


I'm developing a Windows form Application (c#) using vs2010 I have created the .rdlc report and under report data I gave the parameters for each field. then in the form I gave the following code for a button click even of a button named " view report" where the user gives the primary key value to display the relevant report.
but when I run the application and after clicking that button an exception occurs saying
Microsoft.Reporting.WinForms.LocalProcessingException was unhandled
Message=An error occurred during local report processing.
here's the code I gave

private void button1_Click(object sender, EventArgs e)
SqlConnection myconnection1 = new SqlConnection("user=sa;" + "password=123;" + "server=USER-PC\\SQLEXPRESS;" + "Trusted_Connection=Yes;" + "database=Hematology;" + "Connection timeout=30;");
SqlCommand report = new SqlCommand("Select * FROM Patient p, BMarrow b WHERE p.BHT=b.BHT AND p.BHT= '" + textBox1.Text + "';", myconnection1);
SqlDataReader reader2 = report.ExecuteReader();
if (reader2 != null)
if (reader2.Read())

//this form has reportviewer 1 and report1.rdlc is the report viewd in that report viewer
/*I have created 3 datasets under report data and dataset1 stands for the 'Patient' table and datase2
stands for the 'BMarrow table' from those two daasets I have dragged and dropped the attributes
into the text boxes in report1.rdlc*/
ReportParameterCollection reportParameters2 = new ReportParameterCollection();
reportParameters2.Add(new ReportParameter("Name", reader2.GetValue(0).ToString()));
reportParameters2.Add(new ReportParameter("Age", reader2.GetValue(1).ToString()));
reportParameters2.Add(new ReportParameter("Sex", reader2.GetValue(2).ToString()));
reportParameters2.Add(new ReportParameter("Ward", reader2.GetValue(3).ToString()));
reportParameters2.Add(new ReportParameter("BHT", reader2.GetValue(4).ToString()));
reportParameters2.Add(new ReportParameter("Indication", reader2.GetValue(5).ToString()));
reportParameters2.Add(new ReportParameter("BM", reader2.GetValue(6).ToString()));
reportParameters2.Add(new ReportParameter("Difficulty", reader2.GetValue(7).ToString()));
reportParameters2.Add(new ReportParameter("SiteOfAspiration", reader2.GetValue(8).ToString()));
reportParameters2.Add(new ReportParameter("Cellularity", reader2.GetValue(9).ToString()));
reportParameters2.Add(new ReportParameter("Erythropoiesis", reader2.GetValue(10).ToString()));
reportParameters2.Add(new ReportParameter("Granulopoiesis", reader2.GetValue(11).ToString()));
reportParameters2.Add(new ReportParameter("Megakaryocytes", reader2.GetValue(12).ToString()));
reportParameters2.Add(new ReportParameter("Abnormal", reader2.GetValue(13).ToString()));
reportParameters2.Add(new ReportParameter("SpecialStains", reader2.GetValue(14).ToString()));
reportParameters2.Add(new ReportParameter("Lymphocytes", reader2.GetValue(15).ToString()));
reportParameters2.Add(new ReportParameter("Conclusion", reader2.GetValue(16).ToString()));
reportParameters2.Add(new ReportParameter("Date", reader2.GetValue(17).ToString()));




what is wrong with this??? I can't understand :( I'm new to this I tried searching the internet but didn't find a solution

Submitted bychandra prakash (not verified)on Fri, 09/27/2013 - 16:26

how can i modify the rdlc report using c# and
please provide code
and also tell me that how can i pick the .png images using
external images from the folder of images in project

Add new comment