C# 尚未为 Microsoft Reporting Service 中的数据源“Product_Detail”提供数据源实例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13332611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
A data source instance has not been supplied for the data source"Product_Detail" in Microsoft reporting service
提问by Haris
I`m trying to display record in a Report. Data is in the Dataset. but it is not binind to them. When forms load it shows it report layout. But when i click on the button it show errors. below is my code.
我正在尝试在报告中显示记录。数据在数据集中。但它不绑定到他们。当表单加载时,它会显示报告布局。但是当我点击按钮时,它会显示错误。下面是我的代码。
using Microsoft.Reporting.WinForms;
//------------------------------------------------------------------
// <copyright company="Microsoft">
// Copyright (c) Microsoft. All rights reserved.
// </copyright>
//------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ReportsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.reportViewer1.RefreshReport();
}
private void button1_Click(object sender, EventArgs e)
{
System.Data.DataSet ds = GetDataSet();
//reportViewer1.LocalReport.ReportPath = "Report1.rdlc";
ReportDataSource rds = new ReportDataSource("ProductsDataSet", ds.Tables[0]);
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(rds);
this.bindingSource1.DataSource = rds;
this.reportViewer1.RefreshReport();
}
private System.Data.DataSet GetDataSet()
{
System.Data.SqlClient.SqlConnection sqlConn = new System.Data.SqlClient.SqlConnection("Data Source=DELL;Initial Catalog=Products;Integrated Security=True");
sqlConn.Open();
string sql= string.Format ( @"select o.[User], o.OrderDate, o.Quantity, o.OrderDetail, c.ShopName, c.[Address], c.City, c.Ph, p.* from dbo.Clients c,dbo.Product_Service o,Product_D p,Junction j where o.ClientId = c.ClientId
and o.ProductId = j.ProductId
and j.PCode = p.PCode
and o.ClientId = 41
and o.OrderDate='11/9/2012';");
System.Data.SqlClient.SqlDataAdapter ad = new System.Data.SqlClient.SqlDataAdapter(sql, sqlConn);
System.Data.DataSet ds = new System.Data.DataSet();
ad.Fill(ds);
sqlConn.Close();
return ds;
}
}
}
In my data set i have 3 tables. I select the bind source on the top of the reportviewer where a little arrow shows.
在我的数据集中,我有 3 个表。我选择了报告查看器顶部显示小箭头的绑定源。
采纳答案by JustDucky
I bumped into this problem while using version 10 of the ReportViewer while using Visual Studio.Net 2012 to edit code.
我在使用 Visual Studio.Net 2012 编辑代码时使用 ReportViewer 版本 10 时遇到了这个问题。
I found a solution by taking the name of the Data Source in the error message (in the case above, it's "Product_Detail"). I then went into source code view, found the ReportViewer, its DataSources, and then inside its ReportDataSource.
我通过在错误消息中获取数据源的名称找到了一个解决方案(在上面的例子中,它是“Product_Detail”)。然后我进入源代码视图,找到 ReportViewer,它的 DataSources,然后在它的 ReportDataSource 中。
I set the Name property of the ReportDataSource to the same as the Data Source mentioned in the error message (ie "Product_Detail").
我将 ReportDataSource 的 Name 属性设置为与错误消息中提到的 Data Source 相同(即“Product_Detail”)。
I hope this works for you as it did for me.
我希望这对你有用,就像对我一样。
Also, if you have the latitude to use a later version of the ReportViewer control, you may find that this problem either doesn't appear or is easier to solve.
此外,如果您有使用更高版本的 ReportViewer 控件的自由,您可能会发现此问题要么不会出现,要么更容易解决。
回答by Shelby115
"ProductsDataSet" is the name of the DataSource you are giving it. Your Error is saying "A data source instance has not been supplied for the data source“Product_Detail” in Microsoft reporting service"
“ProductsDataSet”是您为其提供的数据源的名称。您的错误是“尚未为 Microsoft 报告服务中的数据源“Product_Detail”提供数据源实例”
I'm assuming you're assigning it the wrong name.
我假设你给它分配了错误的名称。
Try,
尝试,
ReportDataSource rds = new ReportDataSource("Product_Detail", ds.Tables[0]);
If you do have a datasource in the report called "ProductsDataSet" then you probably have 2, in which you'd wanna delete the one you aren't using or assign it a datasource as well.
如果您在报告中确实有一个名为“ProductsDataSet”的数据源,那么您可能有 2 个,您希望在其中删除您不使用的数据源或为其分配一个数据源。
回答by Prince
Dim rptDataSource As ReportDataSource
Try
With Me.ReportViewer1.LocalReport
ReportViewer1.LocalReport.ReportPath = Application.StartupPath & "\RTFLS\Report1.rdlc"
'.DataSources.Clear()
End With
Dim ds As New POAS.CustomersTotalPayment
Dim da As New POAS.CustomersTotalPaymentTableAdapters.PAYMENTSTATUSTableAdapter
da.Fill(ds.PAYMENTSTATUS)
rptDataSource = New ReportDataSource("CustomersTotalPayment", ds.Tables("PAYMENTSTATUS"))
Me.ReportViewer1.LocalReport.DataSources.Add(rptDataSource)
Me.ReportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout)
Catch ex As Exception
MessageBox.Show(ex.Message, My.Application.Info.Title, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Me.ReportViewer1.RefreshReport()
回答by Esmund
if you add another table to the xsd form after adding the report to the report viewer you might get this error.
如果在将报告添加到报告查看器后向 xsd 表单添加另一个表,您可能会收到此错误。
- delete to report viewer and add it again
- set the report to the report viewer
now go to the Load event of the form (that includes the report viewer and add the Fill for new dataset.
private void rptForm_Load(object sender, EventArgs e) { this.vwrpt_TableAdapter1.Fill(this.DataSet1.vwDataset); }
- 删除报告查看器并重新添加
- 将报告设置为报告查看器
现在转到表单的加载事件(包括报告查看器并为新数据集添加填充。
private void rptForm_Load(object sender, EventArgs e) { this.vwrpt_TableAdapter1.Fill(this.DataSet1.vwDataset); }
回答by da Bich
I ran into this in VS2013 in my c# app.. so in case others get here..If you added the dataset in the report designer.. Go to your form, in the designer, click the action arrow on the reportviewer control. Select Rebind Data Sources.
我在 VS2013 中的 c# 应用程序中遇到了这个问题.. 以防其他人到达这里..如果您在报表设计器中添加了数据集.. 转到您的表单,在设计器中,单击报表查看器控件上的操作箭头。选择重新绑定数据源。
回答by vaibhav nag
There was two dataSet created in my rdlc file by default(don't know the reason). Opened RDLC file through notepad and deleted the datasource which was not needed. The values were getting assigned two times to two different dataset. Hope this may help you.
默认情况下,我的 rdlc 文件中创建了两个数据集(不知道原因)。通过记事本打开RDLC文件并删除不需要的数据源。这些值被分配给两个不同的数据集两次。希望这可以帮助你。
回答by Ashraf
Imports Microsoft.Reporting.WebForms
Partial Class Rpt_reports
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim ds As New Custamer
'da.Fill(ds.Tables("custamer")
Dim path As String = Server.MapPath("customerinfo.rdlc")
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.ReportPath = path
ReportViewer1.LocalReport.DataSources.Add(New Microsoft.Reporting.WebForms.ReportDataSource("Rpt_reports", ds.Tables("Custamer")))
ReportViewer1.LocalReport.Refresh()
End If
End Sub
'Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'End Sub
End Class
回答by vihaga yohan94
I know this post bit old but I would like to share my solution with you guys so it might help some.
我知道这篇文章有点旧,但我想与你们分享我的解决方案,所以它可能会对一些人有所帮助。
In my project I got the same error which is "a data source instance has not been supplied for the datasource 'dataset1'". And I used entity framework with code-first method in my project.
在我的项目中,我遇到了同样的错误,即“尚未为数据源‘dataset1’提供数据源实例”。我在我的项目中使用了具有代码优先方法的实体框架。
In order to solve above error I follow below steps.
为了解决上述错误,我按照以下步骤操作。
- Select action arrow on report designer (Report viewer).
- And select the RDLC report from choose report dropdown list.
- Select "Choose Data Source"Choose Data Source
- Then select the data source you wantSelect datasource / binding source from the drop down in highlighted area
- 选择报表设计器(报表查看器)上的操作箭头。
- 然后从选择报告下拉列表中选择 RDLC 报告。
- 选择“选择数据源”选择数据源
- 然后选择您想要的数据源 从突出显示区域的下拉列表中选择数据源/绑定源
回答by Norbert Norbertson
I just had this issue with VS 16.4.6 and the latest report designer extension 15.3.1.
我刚刚在 VS 16.4.6 和最新的报表设计器扩展 15.3.1 中遇到了这个问题。
For me it was caused by giving the data set a slightly different name to the set I'd chosen from the drop down. It took me ages to figure out what was wrong. A hunch suggested it might be an issue. So I renamed the data set to match the source data entity and the error went away.
对我来说,这是因为给数据集的名称与我从下拉列表中选择的数据集略有不同。我花了很长时间才弄清楚出了什么问题。一种预感表明这可能是一个问题。所以我重命名了数据集以匹配源数据实体,错误就消失了。
But why offer the user the chance to call the data set something else and then not test that this actually works?
但是为什么要让用户有机会调用其他数据集,然后不测试它是否真的有效呢?
The report viewer extension is still really poor quality.
报告查看器扩展程序的质量仍然很差。
回答by Eray Balkanli
With respecting to the existing answers, I came across this issue today in VS2015 Professional and fixed it by navigating to Form1.cs (Design), using the action arrow selected the correct datasource and rebind in the end. Please see the image below and follow red, green and purple indications accordingly to see my solution steps.
关于现有答案,我今天在 VS2015 Professional 中遇到了这个问题,并通过导航到 Form1.cs(设计)来修复它,使用操作箭头选择了正确的数据源并最终重新绑定。请查看下图并相应地按照红色、绿色和紫色指示查看我的解决方案步骤。


