C# 尚未为数据源提供数据源实例

C# 尚未为数据源提供数据源实例,c#,reportviewer,reporting-services,C#,Reportviewer,Reporting Services,我当前正在尝试向ReportViewer.net对象动态发送rdl报告 当我这样做的时候,我总是会遇到错误:没有为数据源“blah”提供数据源实例 我试图在运行时在我的代码中定义“废话” ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local; ReportViewer1.LocalReport.ReportPath = ReportFile; ReportViewer1.Local

我当前正在尝试向ReportViewer.net对象动态发送rdl报告

当我这样做的时候,我总是会遇到错误:没有为数据源“blah”提供数据源实例

我试图在运行时在我的代码中定义“废话”

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();
这根本不起作用。我不知道该怎么办。以下是我的rdl文件顶部的摘录:

  <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>

c6a8409e-71a4-4e96-86ad-b300a5b942c3
SQL
数据源=10.555.121.121;初始目录=废话
真的
我所要做的只是从我报告中“blah”中的表中选择*。我需要这样做,因为我需要在ReportViewer中显示许多其他报表实例。为什么微软不让这更容易


提前感谢您……

ReportViewer控件设计为在本地模式下使用RDLC报告文件,而不是RDL报告文件。ReportViewer控件仅用于呈现报表,因此会忽略可能存在的任何数据集和连接信息(即,如果使用RDL文件而不是RDLC文件)。其目的是创建任何连接、查询数据源、将结果放在数据表中并添加这些数据以在调用应用程序中为reportViewer控件创建reportDataSource

从MSDN:

在本地处理模式下,控件打开一个报告定义, 处理它,然后在视图区域中呈现报告。在当地 在处理模式下,可以从.rdlc文件获取报告定义 在文件系统上,从流或中的嵌入式资源 你的申请

更多信息:


另请参见:

您不需要ReportViewer1.DataBind();?感谢您的建议,解决方案并不是那么简单,我必须解析rdl的XML并检索sql并从中构建数据源,然后将数据源命名为与rdl完全相同的名称,然后一切开始工作。您所做的似乎很有趣。也许你应该详细说明你做了什么作为回答,然后接受它?