2012-11-11 7 views
13

のデータソース "Product_Detail"にデータソースインスタンスが提供されていません。レポートにレコードを表示しようとしています。データはデータセットにあります。しかし、それは彼らにとってバイナリではありません。フォームが読み込まれると、レポートのレイアウトが表示されます。しかし、ボタンをクリックするとエラーが表示されます。 は私のコードです。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; 
     } 
    } 
} 

私のデータセットには3つのテーブルがあります。小さな矢印が表示されているレポートビューアの上部にあるバインドソースを選択します。

答えて

21

Visual Studio.Net 2012を使用してコードを編集する際に、Report Viewerのバージョン10を使用しているときにこの問題が発生しました。

エラーメッセージ(上記の場合は「Product_Detail」)でデータソースの名前を取得して解決策を見つけました。私はソースコードビューに入り、ReportViewerとDataSourcesを見つけてからReportDataSourceの中に入れました。

ReportDataSourceのNameプロパティを、エラーメッセージ(「Product_Detail」)に記載されているデータソースと同じに設定しました。

私の場合と同じように、これがうまくいくことを願っています。

さらに、ReportViewerコントロールの新しいバージョンを使用する緯度がある場合、この問題が表示されないか、解決しやすくなることがあります。

9

"ProductsDataSet"は、指定したDataSourceの名前です。 エラーは「データソースインスタンスがMicrosoftレポートサービスの「Product_Detail」に提供されていません」

間違った名前を割り当てているとします。あなたが使用していないものを削除したり、それに割り当てたいと思いますこれを使用して「ProductsDataSet」、あなたはおそらく持っている2というレポートでデータソースを、持っている場合は

てみてください、

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

データソースも同様です。

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

レポートビューアにレポートを追加した後に別のテーブルをxsdフォームに追加すると、このエラーが発生する可能性があります。

  1. ビューアを報告し、再び
  2. それを追加するために、削除は今では、レポートビューアを含み(フォームのLoadイベントに移動し、新しいデータセットの塗りつぶしを追加するレポートビューア
  3. にレポートを設定します。

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

レポートデザイナでデータセットを追加here..If場合には他の人が取得するので、私は、DESで、フォームに移動します.. ..私のC#のアプリでVS2013で、このに走りましたignerで、レポートビューアコントロールのアクション矢印をクリックします。 「データソースの再バインド」を選択します。

+0

ありがとうございます。なぜMicrosoftはそのエラーメッセージにその提案を置くことができなかったのですか? –

関連する問題