Multiple ReportViewer tables RRS feed

  • Question

  • I want to add a table to my rdlc file in Visual Studio 2005.  (I originally wanted to add a subreport but got tired of the nebulous "Error: subreport could not be shown."  Maybe what's causing this problem is causing that one, too.)  I added a table adapter to the same data source the report pulled from, then I dragged a couple of its fields into my table, which is below my old one.  On the report form, I clicked "Rebind Data Sources" and the new binding source and table adapter appeared, and the Fill functions wrote themselves on the top of the form's load event.  

    The report worked fine this morning.  Now, it gives me "A data source instance has not been supplied for the data source 'datLogLogitAssay_tblRejectLevels'"  tblRejectLevels is the name of my new table adapter in the datLogLogitAssay data source.  Any ideas?

    Thanks in advance.


    Monday, February 11, 2008 2:18 PM

All replies

  • You need to clear the other datasources of the report and add only the required ones. It gives this error when there are other datasources.

    Monday, February 11, 2008 2:26 PM
  • you can use subreports, the error you got is because you need a subreport handler where you need to add the subreport datasources

    private DsReport as DataSet

    private sub ReportSources()
    Dim ReporteRecibo As LocalReport = ReportViewer1.LocalReport

    ReporteRecibo.ReportPath = "C:\MyReport.rdlc"

    Dim DsReportas DataSet

    DsReport= functionToObtainData()

     Dim ReportSource1 As New ReportDataSource("DsReport_NomEmpleados", DsReport.NomEmpleados)         
     Dim ReportSource2 As New ReportDataSource("DsReport_Concepts", DsReport.Concepts)


     AddHandler ReportViewer1.LocalReport.SubreportProcessing, AddressOf Me.SubreportProcessingEventHandler

    catch ex as Exception

    end try

    end sub

      Public Sub SubreportProcessingEventHandler(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
            Dim ReportSource As New ReportDataSource("DsReport_Categories", DsReport.Categories)

            e.DataSources.Add(ReportSource )

        End Sub
    Monday, February 11, 2008 5:10 PM
  • I cleared all the datasources from the report form and reclicked "Rebind Data Sources" and it didn't change anything.


    What follows is my restored attempt at using subreports.  Clearing the filters on the table on the subreport doesn't change anything.


    Public Class frmReport

        Private Sub frmReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'datLogLogitAssay.tblLogLogitReport' table. You can move, or remove it, as needed.
            Me.tblLogLogitReportTableAdapter.FillByAsyID(Me.datLogLogitAssay.tblLogLogitReport, Tag)

            Text = frmMain.ActiveMdiChild.Text

            Dim instance As Microsoft.Reporting.WinForms.LocalReport = Me.ReportViewer1.LocalReport

     Some code dealing with report parameters

            AddHandler Me.ReportViewer1.LocalReport.SubreportProcessing, AddressOf AddRejectLevels

            Me.ReportViewer1.LocalReport.EnableExternalImages = True

        End Sub
        Public Sub AddRejectLevels(ByVal sender As Object, ByVal e As Microsoft.Reporting.WinForms.SubreportProcessingEventArgs)
     'None of these lines work.  They each give me "Error: Subreport could not be shown."
            'Me.tblRejectLevelsTableAdapter.FillByasyID(Me.datLogLogitAssay.tblRejectLevels, Me.Tag)
            e.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("AllRejectLevels", Me.datLogLogitAssay.tblRejectLevels))
        End Sub
    End Class

    Tuesday, February 12, 2008 3:54 PM
  • First:remove al datasources from your reportviewer, check the datasource collection and ensure that is no one left.



     in this line of code


    e.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource("AllRejectLevels", Me.datLogLogitAssay.tblRejectLevels))


    Are You sure that "AllRejectLevels" is the table name of your dataset? and me.datLogitAssay.tblRejectLevels is the dataset table?


    check your subreport, and check the datascope



    Tuesday, February 12, 2008 4:10 PM
  • I assume what you mean by "check the datasource collection and ensure that is no one left" is "Delete all data sources from frmReport, click 'Choose Data Sources' and ensure that the 'Data Source Instance' column is blank.  Then under 'Choose Report' select both the subreport and the main report so the table adapters insert themselves."


    "AllRejectLevels" is a made up name and doesn't refer to anything.  Which dataset should it refer to?  I've tried "tblRejectLevels", "datLogLogitAssay_tblRejectLevels" and "tblRejectLevelsTableAdapter" and nothing helped.  I guess technically, the dataset is called "datLogLogitAssay".  I mean, if you open frmReport, datLogLogitAssay is the only thing whose icon resembles that of a DataSet in the toolbox.  That didn't work either.

    Tuesday, February 12, 2008 5:00 PM

    so the name "AllRejectLevels" must be "datLogLogitAssay_tblRejectLevelsTableAdapter" that´s your datascope for subreport.


    i have several reports with one or two subreports,you can use filters in subreports with parameters. i design my reports with typed datasets without table adapters, only table structures, and I fill my dataset "On Foot" not by designer.



    check this website there are usefull tutorials  www.gotreportviewer.com
    Tuesday, February 12, 2008 5:25 PM
  • hey dude: remove the red line



    AddHandler Me.ReportViewer1.LocalReport.SubreportProcessing, AddressOf AddRejectLevels

            Me.ReportViewer1.LocalReport.EnableExternalImages = True

    Tuesday, February 12, 2008 5:31 PM
  • So, I changed the "Me.tblLogLogitReportTableAdapter.FillByAsyID(Me.LogLogitAssay.tblLogLogitReport, Tag)" line to read "Me.ReportViewer.LocalReport.DataSources.Add(New Microsoft.Reporting.WinForms.ReportDataSource('datLogLogitAssay', GetRecords(...))" where GetRecords is a function that accepts a SQL string (like the one from my data source) and returns an OleDb.OleDbDataReader from my Access database.


    It seemed to work fine for my main table, but when I do the same for my datLogLogitAssay_tblRejectLevels, I get the old "A data source instance has not been supplied for the data source 'datLogLogitAssay_tblRejectLevels'.  I rebind the frmReport.  I ensure that 'Choose Data Sources' is accurate and still I get the error message.  Finally, I comment out my new lines, delete the new table from the report, delete the data sources from the frmReport, and I still get the same error even though nothing in my code or form or report is referencing "datLogLogitAssay_tblRejectLevels" anymore. 


    I have to restore a backup to get a report without an error -- very annoying.

    • Proposed as answer by abbbbb Monday, November 3, 2008 6:57 PM
    Tuesday, February 12, 2008 11:29 PM
  • I'm an idiot.  My frmReport wasn't the one being opened.  No wonder when I added a data source to frmReport I still got the "A data source instance has not been supplied for the data source 'datLogLogitAssay_tblRejectLevels" message.


    The FillByasyID code, however, seems to work fine, in case you were curious.


    BTW, when I omit the red line, I get a blank window -- not even the green spinner that says "Report is being generated"

    Wednesday, February 13, 2008 4:11 PM
  • if you got a blank window your report is working with no errors, first you fill your report with data then if you refresh your report the data is flushed and then try to get new data, if there is no data avaliable you get the error "A data source instance Bla BlaBla"

    As I say before, check your data scope, goto your rdlc file, and check the table data scope it must be the dataset table name. if you change the dataset or table name that might be generating the error.
    Wednesday, February 13, 2008 5:10 PM
  • Do you think you could help with this one -- you seem to know a lot





    Friday, February 15, 2008 9:10 AM
  • Hi, I was having same issue once and I was able to solve it.


    When you select Report for the ReportViewer Control, the Form Designer automatically adds code to bind the DataSources to the Report. When later you change the DataSet (xsd file) and update the report file, the Designer generated binding code (in the form which contains the Report Viewer control) is not updated. so this gives error while initializing the report.


    Solution: when ever you change the xsd file , remove the Report Viewer control from the Form and add it again , then select the modified Report file for the control. Now this will add the updated binding info.


    Hope this helps.



    Monday, February 18, 2008 7:08 PM
  • I do my datasources using datasets. As a helper, I created a "generic" MSNetReportViewer.cs form which contains the ReportViewer control that is left unbound and logic to load any rdlc reports and set the report's datasource to a dataset at runtime. Assume there is a report with a subreport inside it, such as a Customer main report with OrderItem subreport. I do the following steps to get it to work (c# environment):

    1) Create a dataset called INVOICE using VisualStudio designer with two tables
            Customers(CustID, CustName) and Orders(CustID, OrderID, ItemName, ItemCost)
    2) Create a report called InvoiceOrderReport.rdlc, this will be the subreport.
            From the report menu, select Data Sources and add INVOICE_Orders to the report.
            From the report menu, select Report Parameters and enter
                CustID for Name
                Integer for Data Type
                Orders.CustID in the Prompt (this is a trick)           
            Add a textbox in the report with =Fields!ItemName
            Add another textbox beside it with =Fields!ItemCost
            Save the report
            In Properties window of Visual Studio, set the Build Action for this file to EmbeddedResource
    3) Create another report called InvoiceMainReport.rdlc.
            From the report menu, select Data Sources and add INVOICE_Customers to the report.
            Add a List to the report and add the next two textbox and subreport inside this list
            Add a textbox in the report with =Fields!CustName
            Add a subreport and right-click subreport and select subreport properties:
                In General tab, set the subreport to InvoiceOrderReport
                In Parameters tab, add CustID for Parameter Name, =Fields!Cust.Value for Parameter Value
            Save the report
            In Properties window of Visual Studio, set the Build Action for this file to EmbeddedResource
    4) In a test form, create an instance of the INVOICE dataset
        INVOICE invoice = new INVOICE();
        adapterCust.Fill(invoice.Customers); //fill all customers from database using adapter
        adapterOrder.Fill(invoice.Orders); //fill all orders for each customer

    After this, add this 4 lines of code that will create the report and bind the data to the two reports internally
        MSNetReportViewer v = new MSNetReportViewer();
        v.SetReportDefinition("InvoiceMainReport", MSNetReportViewer.RDLC_Type.Embedded);

    This way I can repeat the steps 1,2,3 of creating a dataset and report rdlc files for other reports and just use the 4 lines above to run new reports.

    The code for MSNetReportViewer.cs is below:

    using System;


    using System.Collections.Generic;


    using System.ComponentModel;


    using System.Data;


    using System.Drawing;


    using System.Text;


    using System.Windows.Forms;


    namespace MyRpts


    internal partial class MSNetReportViewer : Form



    public enum RDLC_Type






    public MSNetReportViewer()




    private void MSNetReportViewer_Load(object sender, EventArgs e)


    this.reportViewer1.LocalReport.LoadReportDefinition(new System.IO.StringReader(docList[mainReportName].OuterXml));

    foreach (string key in docList.Keys)


    if (key != mainReportName)

    this.reportViewer1.LocalReport.LoadSubreportDefinition(key, new System.IO.StringReader(docList[key].OuterXml));


    this.reportViewer1.LocalReport.SubreportProcessing += new Microsoft.Reporting.WinForms.SubreportProcessingEventHandler(LocalReport_SubreportProcessing);




    System.Collections.Generic.Dictionary<string, System.Xml.XmlDocument> docList = new Dictionary<string, System.Xml.XmlDocument>();

    System.Collections.Generic.Dictionary<string, System.Xml.XmlNamespaceManager> nsmgrList = new Dictionary<string, System.Xml.XmlNamespaceManager>();

    RDLC_Type reportLocation;

    string mainReportName;

    public void SetReportDefinition(string reportName, RDLC_Type reportLocation)


    mainReportName = reportName;

    this.reportLocation = reportLocation;



    private void LoadReportDefinition(string reportName)


    System.IO.Stream s = null;

    if (reportLocation == RDLC_Type.Embedded)


    System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();

    s = assembly.GetManifestResourceStream(new System.Reflection.AssemblyName(assembly.FullName).Name + "." + reportName + ".rdlc");


    else if (reportLocation == RDLC_Type.File)


    s = new System.IO.FileStream(Application.StartupPath + "\\" + reportName + ".rdlc", System.IO.FileMode.Open);


    System.Xml.XmlDocument doc = new System.Xml.XmlDocument();



    System.Xml.XmlNamespaceManager nsmgr = new System.Xml.XmlNamespaceManager(doc.NameTable);

    nsmgr.AddNamespace("rdf", "http://schemas.microsoft.com/sqlserver/reporting/2005/01/reportdefinition");

    nsmgr.AddNamespace("rd", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner");

    docList.Add(reportName, doc);

    nsmgrList.Add(reportName, nsmgr);

    System.Xml.XmlNodeList nodes = doc.SelectNodes("//rdf:Subreport/rdf:ReportName", nsmgr);

    foreach (System.Xml.XmlNode node in nodes)





    public void SetTextbox(string reportName, string textboxName, string value)


    System.Xml.XmlDocument doc = docList[reportName];

    System.Xml.XmlNamespaceManager nsmgr = nsmgrList[reportName];

    System.Xml.XmlNode node = doc.SelectSingleNode("//rdf:Textbox[@Name='" + textboxName + "']/rdf:Value", nsmgr);

    node.InnerText = value;


    DataSet ds;

    public void SetDataSource(DataSet ds)


    this.ds = ds;

    SetReportDataSource(mainReportName, this.reportViewer1.LocalReport.DataSources, null);


    private void SetReportDataSource(string reportName, Microsoft.Reporting.WinForms.ReportDataSourceCollection rdsc,

    Microsoft.Reporting.WinForms.ReportParameterInfoCollection parameters)


    System.Xml.XmlDocument doc = docList[reportName];

    System.Xml.XmlNamespaceManager nsmgr = nsmgrList[reportName];

    System.Xml.XmlNodeList nodes = doc.SelectNodes("/rdf:Report/rdf:DataSets/rdf:DataSet", nsmgr);

    foreach (System.Xml.XmlNode node in nodes)


    string datasourceName = node.Attributes["Name"].InnerText;

    System.Data.DataTable dt = ds.Tables[node.SelectSingleNode("//rd:DataSetInfo/rd:TableName", nsmgr).InnerText];

    string rowFilter = GetRowFilter(dt.TableName, parameters);

    if (rowFilter == "")


    rdsc.Add(new Microsoft.Reporting.WinForms.ReportDataSource(datasourceName, dt));





    rdsc.Add(new Microsoft.Reporting.WinForms.ReportDataSource(datasourceName, new DataView(dt, rowFilter, "", DataViewRowState.CurrentRows)));




    string GetRowFilter(string tableName, Microsoft.Reporting.WinForms.ReportParameterInfoCollection parameters)


    if (parameters == null) return "";

    string rowFilter;

    rowFilter = "";

    foreach (Microsoft.Reporting.WinForms.ReportParameterInfo p in parameters)


    if (p.Prompt.StartsWith(tableName + "."))

    switch (p.DataType)


    case Microsoft.Reporting.WinForms.ParameterDataType.Integer:

    rowFilter += " and " + p.Name + " = " + p.Values[0];



    throw new Exception("Parameter data type '" + p.DataType.ToString() + "' not handled yet!");



    if (rowFilter != "")


    rowFilter = rowFilter.Substring(5);


    return rowFilter;


    void LocalReport_SubreportProcessing(object sender, Microsoft.Reporting.WinForms.SubreportProcessingEventArgs e)


    SetReportDataSource(e.ReportPath, e.DataSources, e.Parameters);






    • Proposed as answer by abbbbb Monday, November 3, 2008 8:13 PM
    • Edited by abbbbb Monday, November 3, 2008 9:55 PM
    Monday, November 3, 2008 7:49 PM
  • I am getting the same issue with the A data source instance has not been supplied for the data source.  I have a chart with one of the metrics doing the drillthrough to a detail report.  I have built the report in another report viewer on the same page and it comes up ok but the first reportviewer where the chart is won't come up.  i have tried adding a source to the xml and adding the high level table qualifiers to all the field names.  still get the same error when going to the report.  Any help would be greatly appreciated


    Wednesday, April 13, 2011 9:25 PM