kxlemeiring
Compliance Validation Auditor
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
200 XP
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.
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.
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.