2012-11-11 27 views
13

Tôi đang cố hiển thị bản ghi trong Báo cáo. Dữ liệu nằm trong Tập dữ liệu. nhưng nó không phải là binind với họ. Khi tải biểu mẫu, nó sẽ hiển thị bố cục báo cáo. Nhưng khi tôi bấm vào nút nó hiển thị lỗi. bên dưới là mã của tôi.Một cá thể nguồn dữ liệu chưa được cung cấp cho nguồn dữ liệu "Product_Detail" trong dịch vụ báo cáo của Microsoft

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

Trong tập dữ liệu của tôi, tôi có 3 bảng. Tôi chọn nguồn liên kết trên đầu trình báo cáo nơi một mũi tên nhỏ hiển thị.

Trả lời

21

Tôi gặp sự cố này khi sử dụng phiên bản 10 của ReportViewer trong khi sử dụng Visual Studio.Net 2012 để chỉnh sửa mã.

Tôi đã tìm thấy giải pháp bằng cách lấy tên của Nguồn dữ liệu trong thông báo lỗi (trong trường hợp trên, đó là "Product_Detail"). Sau đó tôi đã đi vào xem mã nguồn, tìm thấy ReportViewer, các DataSources của nó, và sau đó bên trong ReportDataSource của nó.

Tôi đặt thuộc tính Tên của ReportDataSource thành giống như Nguồn dữ liệu được đề cập trong thông báo lỗi (ví dụ: "Product_Detail").

Tôi hy vọng điều này phù hợp với bạn như đã làm cho tôi.

Ngoài ra, nếu bạn có vĩ độ sử dụng phiên bản sau của điều khiển ReportViewer, bạn có thể thấy rằng sự cố này không xuất hiện hoặc dễ giải quyết hơn.

9

"Sản phẩmDataSet" là tên của DataSource bạn đang cung cấp. Lỗi của bạn là nói "Một cá thể nguồn dữ liệu chưa được cung cấp cho nguồn dữ liệu" Product_Detail "trong dịch vụ báo cáo của Microsoft"

Tôi giả định bạn đang gán sai tên.

Cố gắng,

ReportDataSource rds = new ReportDataSource("Product_Detail", ds.Tables[0]); 

Nếu bạn có một nguồn dữ liệu trong báo cáo mang tên "ProductsDataSet", sau đó bạn có thể có 2, trong đó bạn sẽ muốn xóa một bạn không sử dụng hoặc gán cho nó một cũng như nguồn dữ liệu.

0
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() 
0

nếu bạn thêm một bảng khác vào biểu mẫu xsd sau khi thêm báo cáo vào trình xem báo cáo, bạn có thể gặp phải lỗi này.

  1. xóa để báo cáo người xem và thêm nó một lần nữa
  2. thiết lập các báo cáo để người xem báo cáo
  3. bây giờ đi đến sự kiện Load của form (trong đó bao gồm người xem báo cáo và thêm Fill cho tập dữ liệu mới .

    private void rptForm_Load(object sender, EventArgs e) { 
        this.vwrpt_TableAdapter1.Fill(this.DataSet1.vwDataset); 
    } 
    
7

tôi chạy vào này trong VS2013 trong C# ứng dụng của tôi .. như vậy trong trường hợp người khác có được here..If bạn thêm các tập dữ liệu trong thiết kế báo cáo .. Đi đến biểu mẫu của bạn, trong des igner, nhấp vào mũi tên hành động trên điều khiển reportviewer. Chọn Rebind Data Sources.

+0

Cảm ơn bạn. Bây giờ tại sao Microsoft không thể đưa ra gợi ý đó trong thông báo lỗi của họ. –