【问题标题】:A data source instance has not been supplied for the data source尚未为数据源提供数据源实例
【发布时间】:2011-04-30 22:56:44
【问题描述】:

我目前正在尝试将 rdl 报告动态发送到我的 ReportViewer .net 对象。

执行此操作时不断收到错误消息:尚未为数据源“blah”提供数据源实例

我试图在运行时在我的代码中定义“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>

我要做的只是从报告中“blah”的表格中选择 *。我需要它来工作,因为我需要在 ReportViewer 中显示许多其他报表实例。为什么微软不让这更容易?

提前谢谢大家...

【问题讨论】:

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

标签: c# reportviewer reporting-services


【解决方案1】:

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

来自 MSDN:

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

更多信息:Adding and Configuring the ReportViewer Controls

另见:When to use RDLC over RDL reports?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多