How to set parameters with print multiple in one go with different headings in rdlc report with VB.NET

34 Views Asked by At

I'm trying to set parameters with print multiple in one go with different headings in rdlc report with VB.NET I have the code below. I tried with the code below which came out the result only COPY1

Please Guide me

Thanks

Thanks

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
    Private Sub original()
        Dim table As New DataTable()
        table.Columns.Add("value", GetType(String))
        table.Columns.Add("price", GetType(String))
        table.Columns.Add("quantity", GetType(Double))
        table.Rows.Add("test1", "10", "20")
        table.Rows.Add("test2", "10", "20")
        Dim reportDataSource1 = New ReportDataSource("DataSet1", table)
        Me.ReportViewer1.LocalReport.DataSources.Clear()
        Dim reportParameters As New ReportParameterCollection()
        reportParameters.Add(New ReportParameter("paramHeader", "ORIGINAL"))
        Me.ReportViewer1.LocalReport.SetParameters(reportParameters)
        Me.ReportViewer1.LocalReport.DataSources.Add(reportDataSource1)
        Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "Datatable_in_ReportViewer.Report1.rdlc"
        Me.ReportViewer1.RefreshReport()
    End Sub
    Private Sub copy1()
        Dim table As New DataTable()
        table.Columns.Add("value", GetType(String))
        table.Columns.Add("price", GetType(String))
        table.Columns.Add("quantity", GetType(Double))

        table.Rows.Add("test1", "10", "20")
        table.Rows.Add("test2", "10", "20")
        Dim reportDataSource1 = New ReportDataSource("DataSet1", table)
        Me.ReportViewer1.LocalReport.DataSources.Clear()
        Dim reportParameters As New ReportParameterCollection()
        reportParameters.Add(New ReportParameter("paramHeader", "COPY1"))
        Me.ReportViewer1.LocalReport.SetParameters(reportParameters)
        Me.ReportViewer1.LocalReport.DataSources.Add(reportDataSource1)
        Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "Datatable_in_ReportViewer.Report1.rdlc"
        Me.ReportViewer1.RefreshReport()
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        original()
        copy1()
    End Sub
End Class
1

There are 1 best solutions below

0
HardcoreGamer On

Parameter only have single value, you overwrite the second time you add.

reportParameters.Add(New ReportParameter("paramHeader", "ORIGINAL"))
reportParameters.Add(New ReportParameter("paramHeader", "COPY1"))

Instead, you can try add a new column Copys to group two data in same table, with value ORIGINAL and Copy1

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles 
MyBase.Load

End Sub
Private Sub original(ByRef table as DataTable))
    table.Rows.Add("original","test1", "10", "20")
    table.Rows.Add("original","test2", "10", "20")
End Sub
Private Sub copy1(ByRef table as DataTable)
    table.Rows.Add("copy1","test1", "10", "20")
    table.Rows.Add("copy1","test2", "10", "20")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim table As New DataTable()
    table.Columns.Add("Copys", GetType(String))
    table.Columns.Add("value", GetType(String))
    table.Columns.Add("price", GetType(String))
    table.Columns.Add("quantity", GetType(Double))
    original(table)
    copy1(table)
    
    Dim reportDataSource1 = New ReportDataSource("DataSet1", table)
    Me.ReportViewer1.LocalReport.DataSources.Clear()
    Dim reportParameters As New ReportParameterCollection()
    Me.ReportViewer1.LocalReport.SetParameters(reportParameters)
    Me.ReportViewer1.LocalReport.DataSources.Add(reportDataSource1)
    Me.ReportViewer1.LocalReport.ReportEmbeddedResource = "Datatable_in_ReportViewer.Report1.rdlc"
    Me.ReportViewer1.RefreshReport()
End Sub
End Class

You will need to edit the .rdlc report table and group it by the new column Copys