4

I'm currently trying to dynamically send an rdl report to my ReportViewer .net object.

I keep getting the error when I do it: A data source instance has not been supplied for the data source "blah"

I'm trying to define "blah" in my code behind at runtime.

ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local;
  ReportViewer1.LocalReport.ReportPath = ReportFile;
  ReportViewer1.LocalReport.DataSources.Clear();
  Microsoft.Reporting.WebForms.ReportDataSource rds = new Microsoft.Reporting.WebForms.ReportDataSource();
  rds.Name = "blah";
  ReportViewer1.LocalReport.DataSources.Add(rds);
  ReportViewer1.DocumentMapCollapsed = true;
  ReportViewer1.LocalReport.Refresh();

this is not working by a long shot. I'm not sure what I'm supposed to do. here is an extract of the top of my rdl file:

  <DataSource Name="blah">
      <rd:DataSourceID>c6a8409e-71a4-4e96-86ad-b300a5b942c3</rd:DataSourceID>
      <ConnectionProperties>
        <DataProvider>SQL</DataProvider>
        <ConnectString>Data Source=10.555.121.121;Initial Catalog=blah</ConnectString>
        <IntegratedSecurity>true</IntegratedSecurity>
      </ConnectionProperties>
    </DataSource>
  </DataSources>

All I'm trying to do is simply select * from a table in "blah" in my report. I need this to work because I have many other report instances I need to show inside my ReportViewer. Why doesn't Microsoft make this easier?

Thanks in advance anybody...

George Johnston
  • 31,652
  • 27
  • 127
  • 172
Lyle
  • 419
  • 1
  • 6
  • 26
  • Dont you need ReportViewer1.DataBind();? – Raymund Oct 26 '10 at 23:05
  • 2
    Thanks for your suggestion, the solution was not that easy, I had to parse the XML of the rdl and retrieve the sql and build a datasource from it then name the datasource the same exact name as the rdl, after that everything started to work. – Lyle Oct 28 '10 at 15:51
  • 2
    What you were doing seems interesting. Maybe you should elaborate on what you did as an answer an then accept it? – Lzh Aug 26 '14 at 07:36

1 Answers1

0

The ReportViewer control is designed to work in local mode with RDLC report files, not RDL report files. The ReportViewer control is only intended to render the report and therefore ignores any dataset and connection information that may be present (i.e. if you use an RDL file instead of an RDLC file). The intention is that you create any connections, query data sources, put the results in DataTables and add these to create the reportDataSource(s) for the reportViewer control in the calling application.

From MSDN:

In local processing mode, the control opens a report definition, processes it, and then renders the report in the view area. In local processing mode, you can get the report definition from a .rdlc file on the file system, from a stream, or from an embedded resource in your application.

More information: Adding and Configuring the ReportViewer Controls

See also: When to use RDLC over RDL reports?

Community
  • 1
  • 1
Nathan Griffiths
  • 12,277
  • 2
  • 34
  • 51