Search code examples
vb.netreporting-servicesrdlcrdldynamic-rdlc-generation

How to use vb.net dataset on RDL or RDLC?


I have a simple vb.net app.

Module Module1
    Sub Main()
        ' Two DataTables.
        Dim table1 As DataTable = New DataTable("patients")
        table1.Columns.Add("name")
        table1.Columns.Add("id")
        table1.Rows.Add("sam", 1)
        table1.Rows.Add("mark", 2)

        Dim table2 As DataTable = New DataTable("medications")
        table2.Columns.Add("id")
        table2.Columns.Add("medication")
        table2.Rows.Add(1, "atenolol")
        table2.Rows.Add(2, "amoxicillin")

        ' Create a DataSet. Put both tables in it.
        Dim set1 As DataSet = New DataSet("office")
        set1.Tables.Add(table1)
        set1.Tables.Add(table2)

    End Sub
End Module

I would like use RDL or RDLC to display one of the table in my dataset (set1). Can I do that? if yes, how can I do it??

I want (or I am hoping) to run RDL or RDLC without the need of having a SQL connection or Access MDB Database, nor intermediary XML or CSV file in file system..

thank you for reading my question.


Solution

  • Finally I got it working.

    I was missing this step to add xsd. see screenshot below.

    So this is my final code ANOTHER IMPORTANT POINT IS THE DATATABLE in XSD must be the same name as your DATATABLE build in the form_load

    Imports Microsoft.Reporting.WinForms
    
    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    
            Dim DataTable1 As DataTable = New DataTable("patients")
            DataTable1.Columns.Add("name")
            DataTable1.Columns.Add("id")
            DataTable1.Rows.Add("sam", 1)
            DataTable1.Rows.Add("mark", 2)
    
    
            ReportViewer1.LocalReport.ReportPath = "C:\IT\MISC\Visual Studio Project PLAYGROUND\WinFormPlay\Report\Report1.rdlc"
    
    
            ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("DataSet1", DataTable1))
    
            Me.ReportViewer1.RefreshReport()
    
    
        End Sub
    
    End Class
    

    enter image description here