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.
FOR YOUR OWN SAFETY, PLEASE:
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.

Comments
Help
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 robbyde02@hotmail.com
help
Hi,
can you send the same code in c# please ??
please help me, i need it for my project.
my email : wayde.van.dyk@gmail.com
Thank you very much. This is
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.
Add new comment