Load RDLC Report Using Report Viewer Programmatically

Submitted by: 
Visitors have accessed this post 167610 times.

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.

  1. Private Sub frmReport_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
  2. Dim rptDataSource As ReportDataSource
  4. Try
  5. With Me.ReportViewer1.LocalReport
  6. .ReportPath = "Reports\" & strReport & ".rdlc"
  7. .DataSources.Clear()
  8. End With
  10. Select strReport
  11. Case "Employees"
  12. Dim ds As New Load_RDLC_Report_Programmatically.EmployeesDataSet
  13. Dim da As New Load_RDLC_Report_Programmatically.EmployeesDataSetTableAdapters.EmployeesTableAdapter
  15. da.Fill(ds.Employees)
  17. ' Use the same name as defined in the report Data Source Definition
  18. rptDataSource = New ReportDataSource("EmployeesDataSet", ds.Tables("Employees"))
  19. Case "Customers"
  20. Dim ds As New Load_RDLC_Report_Programmatically.CustomersDataSet
  21. Dim da As New Load_RDLC_Report_Programmatically.CustomersDataSetTableAdapters.CustomersTableAdapter
  23. da.Fill(ds.Customers)
  25. ' Use the same name as defined in the report Data Source Definition
  26. rptDataSource = New ReportDataSource("CustomersDataSet", ds.Tables("Customers"))
  27. End Select
  29. Me.ReportViewer1.LocalReport.DataSources.Add(rptDataSource)
  31. Me.ReportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout)
  32. Catch ex As Exception
  33. MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
  34. End Try
  35. 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.


thank you. this is what i am looking since last week.

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


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

In line 15 is it appropriate to write
to pass the parameter from the txtEmployeeID textbox.
If not, then how can this be implemented
Help a newbie

Yes, that's correct. I believe you know how to create another query with parameter under the dataset designer.

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..

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

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. }

Hey can you please explain your code,Thanx

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.

can you send the same code in c# please ??
please help me, i need it for my project.
my email : [email protected]

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]

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.