【问题标题】:A data source instance has not been supplied for the data source 'DataSet1'尚未为数据源“DataSet1”提供数据源实例
【发布时间】:2017-05-08 09:36:23
【问题描述】:

我正在通过创建数据集创建我的 rdlc 报告,但是当我运行我的报告时出现此错误“尚未为数据源 'DataSet1' 提供数据源实例”我也更改了数据集名称但没有改进。我给数据源通过智能标签传递给报表查看器。

【问题讨论】:

  • 也许你没有 new 数据集对象,即创建一个新实例......很难确定你到底想做什么而不显示导致你出错的代码
  • 请尝试写正确的英文。许多读者(包括我自己)不是母语人士,您希望您的问题尽可能容易理解。
  • @vonbrand 他的英语很好。没必要批评……真的
  • 您是否要迁移报告?

标签: c# asp.net


【解决方案1】:

您似乎还没有将数据源设置为报表查看器数据源。

您可以通过多种方式检查这一点,我建议您通过以下两种方式:

在 aspx 文件中,在 ReportViewer 标记处,确保您在 <LocalReport> 标记中有 <DataSources> 设置。查看我的示例代码:

<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
    <LocalReport ReportPath="Report.rdlc">
         <DataSources>
             <rsweb:ReportDataSource DataSourceId="SqlDataSource1" Name="DataSet1" />
         </DataSources>
    </LocalReport>
</rsweb:ReportViewer>

必须设置&lt;ReportDataSource&gt;标签的DataSourceId属性。

否则您可以在设计视图中将报表数据源实例设置为 ReportViewer。见下图:

ReportViewer 任务 > 选择数据源 > 数据源实例

【讨论】:

  • 我有一些代码可以在运行时构建一个 ASPNET DataTable,我想在 ReportViewer 中呈现。你能告诉我如何在运行时配置 ReportViewer 的数据源吗?
【解决方案2】:

如果您通过代码将 DataSource 绑定到 Report,

DataSet name "FinancialRatios" and Table name "FinInfo"

我尝试如下分别指定数据集和表名

ReportDataSource datasource = new ReportDataSource("FinancialRatios", dsFinRatios.Tables[0]);

ReportDataSource datasource = new ReportDataSource("FinInfo", dsFinRatios.Tables[0]);

在这两种情况下,错误都是“没有为数据源 'FinancialRatios_FinInfo' 提供数据源实例。”

所以我将 DataSource 设置为错误中提到的“FinancialRatios_FinInfo”并且它起作用了。

ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/FinRatioReport.rdlc");
ReportDataSource datasource = new ReportDataSource("FinancialRatios_FinInfo", dsFinRatios.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);

【讨论】:

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