【问题标题】:rdlc report - ‘A data source instance has not been supplied for the data source’ errorrdlc 报告 - “尚未为数据源提供数据源实例”错误
【发布时间】:2013-03-15 15:16:41
【问题描述】:

在我的 ASP.Net 网页 项目中,我创建了一个新网页并将脚本管理器控件拖到它上面,然后我使用创建了一个新的 rdlc 报告向导并配置开始检索数据的数据集(以显示 Products 表的 3 个字段:ProductName、quatityPerUnit、Price)。

在接下来的步骤中,我插入了一个新的 Reportviewer 并将其绑定到之前创建的报表,然后我再次通过打开 dataset1.xsd 文件并单击预览数据来验证是否检索到数据。

这是我的网页正文代码:

<body>
    <form id="form1" runat="server">
    <div>

        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt">
            <LocalReport ReportPath="Reports\MyRdlcReport.rdlc">
                <DataSources>
                    <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="dsProducts" />
                </DataSources>
            </LocalReport>
        </rsweb:ReportViewer>
        <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData" TypeName="WebApplication1.dsProductsTableAdapters.ProductsTableAdapter">

        </asp:ObjectDataSource>        
    </div>
    </form>
</body>

但是当我运行项目时,我得到了下一个错误:没有为数据源'dataSource1'提供数据源实例,我试图在网上找到一个类似的案例但是什么都没找到,请帮忙?

【问题讨论】:

  • 您是否请求迁移报告?

标签: asp.net visual-studio-2012 reporting rdlc


【解决方案1】:

你必须意识到最后一步是谁defining of datasource

链接:http://ruchitech.blogspot.fr/2012/07/how-to-create-rdlc-report-in-c.html

注意:请参阅选择数据源

【讨论】:

  • 已经为报表定义了数据源,并且报表已经分配给报表查看器,我已经看到了你的链接,我认为一切都完成了...
  • 可视化您的代码并检查此行是否存在:rdlc.DataSource = ....
  • 谢谢你。我错过了选择数据源的屏幕截图下的步骤。我以为既然我在 RDLC 设计器中定义了它,它就完成了。选择数据源后,重新绑定它们
【解决方案2】:

最后我找到了原因,它是一个不对应的 Tablix 数据集名称属性。我不得不将它从 dataSet1 重命名为 dsProducts。

【讨论】:

    【解决方案3】:
    // ReportViewer1.LocalReport.DataSources.Clear();
    ReportViewer1.LocalReport.DataSources.Add(Student);
    

    在页面加载中,确保ReportViewer 的上述清除函数被作为注释或删除以避免Data source 实例未提供错误。

    【讨论】:

      【解决方案4】:

      Visual Studio 13 提供了一个优雅的解决方案来处理 sql server 存储过程中的参数:

      报表查看器 使用报表查看器的 Web 版本创建 Web 报表的步骤

      1. 使用网站创建 Web 表单/添加新项目

      2. 将 ReportViewer 拖到网页上

      3. 选择创建新报告 (rdlc)
      4. 为报告选择数据源(确保在保存前重命名)
      5. 使用报告生成器在报告中放置字段。
      6. 保存报告,然后将 report1.rdlc 的默认值重命名为所需的名称
      7. 将报告和网页移至所需目录
      8. 转到网页报告查看器任务并选择报告。
      9. 然后选择数据源(可以在数据源中添加报表的参数)

      选择新建数据源,否则报告会报错:

      尚未为数据源提供数据源实例”

      1. 将出现一个显示各种数据源的新屏幕。一般选择SQL数据

      2. 选择指定自定义 SLQ 语句,然后点击 NEXT

      3. 选择存储过程或选择 SLQ 语句并使用查询生成器。选择存储过程将允许用户为存储过程的参数选择控件。然后,向导将正确配置 Web 代码,从而无需输入以下 vb 代码:

      Protected Sub ReportViewer1_Load(sender As Object, e As EventArgs) Handles ReportViewer1.Load
          Dim Parm As New ReportParameter("BillingReportParm1", Profile.TherapistNo)
          ReportViewer1.LocalReport.SetParameters(Parm)
          ReportViewer1.LocalReport.Refresh()
      End Sub
      
      1. 完成的 HTML 代码示例如下所示:

      <asp:Content ID="Content2" ContentPlaceHolderID="cpMC" Runat="Server">
      	<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt" WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" Height="383px" Width="721px">
      		<LocalReport ReportPath="Reports\BillingPendingRpt.rdlc">
      			<DataSources>
      				<rsweb:ReportDataSource DataSourceId="SqlDataPendRpt" Name="BillingPendingRptDataSet" />
      			</DataSources>
      		</LocalReport>
      	</rsweb:ReportViewer>
      	<asp:SqlDataSource ID="SqlDataPendRpt" runat="server" ConnectionString="<%$ ConnectionStrings:MMBDataConnectionString %>" SelectCommand="sp_WorkHour_Rpt" SelectCommandType="StoredProcedure">
      		<SelectParameters>
      			<asp:ProfileParameter Name="Therapist" PropertyName="TherapistNo" Type="String" />
      		</SelectParameters>
      	</asp:SqlDataSource>
      </asp:Content>

      【讨论】:

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