none
The ubiquitous "A data source instance has not been supplied..."

    Question

  • I have a simple report based on a Project business object.  I've dragged and dropped a reportviewer control and a bindingsource, named "ProjectBindingSource" control onto my form.  I dragged and dropped several fields from the Project business object onto my .rdlc report form.  In the code called before refreshing the reportviewer, I've attempted to set the datasource property of the ProjectBindingSource via the following statements:

    Project aProj = Project.GetProject(projID);
    ProjectBindingSource.DataSource = aProj;

    Single-stepping through the code, aProj gets populated with the project information in the first statement and it should be bound to the report via the ProjectBindingSource; however, I'm still getting a "A data source instance has not been supplied for the data source 'Library_Project'. error when the report is called up.

    Where should I look to resolve this problem?

    Tuesday, November 21, 2006 1:40 PM

All replies

  • Either in your Form's InitializeComponent() method or just before you call RefreshReport(), you should have some code like the following:

        Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new   Microsoft.Reporting.WinForms.ReportDataSource();
      reportDataSource1.Name = "Library_Project";
      reportDataSource1.Value =
    this.ProjectBindingSource;
      this.reportViewer1.LocalReport.DataSources.Add(reportDataSource1);

    Is that the case?

    Thursday, November 23, 2006 1:11 AM
  • Yes, I have code similar to that in the routine that's selected from the report menu in my application.
    Thursday, November 23, 2006 3:39 PM
  • Could you have more than one call to RefreshReport? As you are debugging, stop at the call to RefreshReport and look at the value of reportViewer.LocalReport.DataSources.  Do you see your data source in the collection?  If you step over the call, does it throw an exception?  (Too see the exceptions thrown within the ReportViewer code, you may have to go to VS Tools\Options\Debugging\General and uncheck "Enable Just My Code".  In the Debug menu, enable catching all CLR exceptions.)

    -Albert

    Wednesday, November 29, 2006 11:27 PM