Obtain data source name from .rdlc RRS feed

  • Question

  • I'm using ReportViewer in WPF application.

    I need to load the data for the report at runtime, as well setting the ReportPath.

    So, I need to provide an instance of ReportDataSource to the LocalReport, but I don't know the DataSourceName that the .rdlc uses. And if I don't the right name, the report give me an error:

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

    I don't know that the .rdlc needs "DataSet1". How can I obtain this name from .rdlc?

    Here's some code:

    var reportDataSource = new ReportDataSource("WHAT TO PASS HERE?");
                reportDataSource.Value = data.Tables[0];
                reportViewer.LocalReport.ReportPath = reportPath;

    Take a look at WPF FlashMessage

    Tuesday, September 11, 2012 8:23 PM

All replies

  • Ok, I don't know if there's a simple way to do it, but I opened the .rdlc (a xml file) and looked for the first DataSet, and then retrieve the DataSet Name attribute.

    var documentoRDLC = XDocument.Load(caminhoRelatorio);
    var namespaceManager = new XmlNamespaceManager(new NameTable());
                namespaceManager.AddNamespace("x", "");
    var elementoDataSet = documentoRDLC.XPathSelectElement("//x:DataSets/x:DataSet[1]", namespaceManager);
               var dataSetName = elementoDataSet.Attribute("Name").Value;

    Take a look at WPF FlashMessage

    Wednesday, September 12, 2012 12:04 PM