• We just launched and are currently in beta. Join us as we build and grow the community.

Load RDLC Report Using Report Viewer Programmatically

kxlemeiring

Compliance Validation Auditor
K Rep
0
0
0
Rep
0
K Vouches
0
0
0
Vouches
0
Posts
151
Likes
183
Bits
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.

  1. Private

    Sub

    frmReport_Load(

    sender As

    System.

    Object

    , e As

    System.

    EventArgs

    )

    Handles

    MyBase

    .

    Load
  2. Dim

    rptDataSource As

    ReportDataSource

  3. Try
  4. With

    Me

    .

    ReportViewer1

    .

    LocalReport
  5. .

    ReportPath

    =

    "Reports\"

    &

    strReport &

    ".rdlc"
  6. .

    DataSources

    .

    Clear

    (

    )
  7. End

    With

  8. Select

    strReport
  9. Case

    "Employees"
  10. Dim

    ds As

    New

    Load_RDLC_Report_Programmatically.

    EmployeesDataSet
  11. Dim

    da As

    New

    Load_RDLC_Report_Programmatically.

    EmployeesDataSetTableAdapters

    .

    EmployeesTableAdapter

  12. da.

    Fill

    (

    ds.

    Employees

    )

  13. ' Use the same name as defined in the report Data Source Definition
  14. rptDataSource =

    New

    ReportDataSource(

    "EmployeesDataSet"

    , ds.

    Tables

    (

    "Employees"

    )

    )
  15. Case

    "Customers"
  16. Dim

    ds As

    New

    Load_RDLC_Report_Programmatically.

    CustomersDataSet
  17. Dim

    da As

    New

    Load_RDLC_Report_Programmatically.

    CustomersDataSetTableAdapters

    .

    CustomersTableAdapter

  18. da.

    Fill

    (

    ds.

    Customers

    )

  19. ' Use the same name as defined in the report Data Source Definition
  20. rptDataSource =

    New

    ReportDataSource(

    "CustomersDataSet"

    , ds.

    Tables

    (

    "Customers"

    )

    )
  21. End

    Select

  22. Me

    .

    ReportViewer1

    .

    LocalReport

    .

    DataSources

    .

    Add

    (

    rptDataSource)

  23. Me

    .

    ReportViewer1

    .

    SetDisplayMode

    (

    Microsoft.

    Reporting

    .

    WinForms

    .

    DisplayMode

    .

    PrintLayout

    )
  24. Catch

    ex As

    Exception
  25. MessageBox.

    Show

    (

    ex.

    Message

    , My.

    Application

    .

    Info

    .

    Title

    , MessageBoxButtons.

    OK

    , MessageBoxIcon.

    Error

    )
  26. End

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

 

452,496

329,696

329,704

Top