none
Windows Forms Reportviewer - Using Custom datatable RRS feed

  • Question

  • Hi,

    My program creates a datatable with extra columns for specific information required for the report.

    I have DataSet1.xsd within my project that contains a "Scores" datatable that has all the columns for my custom datatable.

    I have created a report "Report3.rdlc" using the fields from the "Scores" datatable.

    I have a form "FrmRptViewer" with only a Reportviewer "RView" control, a DataSet1 component and a ScoresBindingSource bound to the Scores datatable.

    I show the form using an overload that passes a ReportType and the custom datatable as follows;

    Public Overloads Sub Show(ByVal RptType As Integer, ByRef myDTable As DataTable)
    
            Try
                myDataTable = myDTable
                myRptType = RptType
                MyBase.Show()
            Catch ex As Exception
                MessageBox.Show("Error : " & ex.Message, "Overloads Show Form Report Viewer", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
    
        End Sub
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            
            RView.Reset()
            RView.LocalReport.DataSources.Clear()
            RView.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local
            RView.LocalReport.ReportEmbeddedResource = "MyApp.Report3.rdlc"
    
    
            Dim customReportData As New ReportDataSource
            customReportData.Name = "DataTableScores"
            customReportData.Value = ScoresBindingSource
            RView.LocalReport.DisplayName = "Report3"
    
            '--- pass the reportviewer our datasource
    
            RView.LocalReport.DataSources.Add(customReportData)
    
            RView.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.Normal)
            RView.DocumentMapCollapsed = False
            RView.RefreshReport()
            Me.RView.RefreshReport()
        End Sub

    When I run the program I get the error message;

    "A data source instance has not been supplied for the data source "DataSet1".

    Can someone let me know what I have missed here please.

    Thanks in advance,

    John


    Monday, August 8, 2016 7:54 AM

Answers

  • Well after much Googling I finally worked out the solution;

    I just had to change the LocalReport.DataSource name to "DataSet1" as per below.

    Try
                RView.Reset()
                RView.LocalReport.DataSources.Clear()
                RView.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local
                RView.LocalReport.ReportEmbeddedResource = "MyApp.Report3.rdlc"
               
                RView.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", myDataTable))
                RView.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.Normal)
                RView.DocumentMapCollapsed = False
                RView.RefreshReport()
                Me.RView.RefreshReport()
            Catch ex As Exception
                MessageBox.Show("Error : " & ex.Message, "Load Form Report Viewer", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try

    Even though my report fields were set using the "Scores" datatable, the report referenced it as "DataSet1" per below screenshot.

    I hope this helps others trying to do the same thing.

    • Marked as answer by Rinso Tuesday, August 16, 2016 4:47 AM
    Tuesday, August 16, 2016 4:47 AM