尚未为Microsoft报告服务中的数据源"Product_Detail"提供数据源实例

Har*_*ris 19 c# reportviewer rdlc

我试图在报告中显示记录.数据位于数据集中.但它并不适合他们.表单加载时,它会显示报表布局.但是,当我点击按钮时,它显示错误.下面是我的代码.

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;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在我的数据集中,我有3个表.我在reportviewer顶部选择了一个小箭头显示的绑定源.

小智 31

我在使用Visual Studio.Net 2012编辑代码时使用ReportViewer的第10版时遇到了这个问题.

我通过在错误消息中获取数据源的名称找到了一个解决方案(在上面的例子中,它是"Product_Detail").然后我进入源代码视图,找到了ReportViewer,它的DataSources,然后是它的ReportDataSource.

我将ReportDataSource的Name属性设置为与错误消息中提到的数据源相同(即"Product_Detail").

我希望这对你有用,就像它对我一样.

此外,如果您有使用更高版本的ReportViewer控件的自由度,您可能会发现此问题不会出现或更容易解决.


She*_*115 12

"ProductsDataSet"是您提供的DataSource的名称.您的错误是说"Microsoft报告服务中的数据源"Product_Detail"尚未提供数据源实例"

我假设你给它指的是错误的名字.

尝试,

ReportDataSource rds = new ReportDataSource("Product_Detail", ds.Tables[0]);
Run Code Online (Sandbox Code Playgroud)

如果你在报告中有一个名为"ProductsDataSet"的数据源,那么你可能有2个,你要删除你没有使用的数据源,或者为它分配一个数据源.


da *_*ich 8

我在我的c#app中遇到了这个VS2013.所以万一其他人到了这里..如果你在报表设计器中添加了数据集..转到你的表单,在设计器中,单击reportviewer控件上的动作箭头.选择重新绑定数据源.