尚未为数据源“Product_Detail"提供数据源实例.在 Microsoft 报告服务中 [英] A data source instance has not been supplied for the data source"Product_Detail" in Microsoft reporting service

查看:44
本文介绍了尚未为数据源“Product_Detail"提供数据源实例.在 Microsoft 报告服务中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在报告中显示记录.数据在数据集中.但它不绑定到他们.当表单加载时,它会显示报告布局.但是当我点击按钮时,它会显示错误.下面是我的代码.

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;
        }
    }
}

在我的数据集中,我有 3 个表.我选择了报告查看器顶部显示小箭头的绑定源.

In my data set i have 3 tables. I select the bind source on the top of the reportviewer where a little arrow shows.

推荐答案

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

I bumped into this problem while using version 10 of the ReportViewer while using Visual Studio.Net 2012 to edit code.

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

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.

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

I set the Name property of the ReportDataSource to the same as the Data Source mentioned in the error message (ie "Product_Detail").

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

I hope this works for you as it did for me.

此外,如果您有足够的空间使用更高版本的 ReportViewer 控件,您可能会发现这个问题要么不会出现,要么更容易解决.

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.

这篇关于尚未为数据源“Product_Detail"提供数据源实例.在 Microsoft 报告服务中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆