2012-03-06 22 views
0

EDIT:デバッグ用にストアドプロシージャではなくSQLステートメントを実行しています。エラーが発生しました。データソースインスタンス 'DataSet2'が提供されていません。私もReportViewer1.Reset()を取り除きました。Reportviewerが正しくレポートを表示しない

ReportViewerがReports.aspxの "RunReportButton"ボタンをクリックした後にレポートを表示しない理由を理解しようとしています。 @PersonIDと@Categoryの2つのパラメータを持つSQL文があります。このSQL文は、PersonID = @PersonIDおよび@Category = Categoryを持つPersonExerciseテーブルのすべてのレコードを検索します。このSQL文に基づいてデータセットを実行し、それをreportDataSourceのreports.aspxのコードの後ろに渡します。

次に、Report1.rdlcを作成し、それを自分のデータセットdsCardioにリンクしました。私はExerciseDate、Distance、Speedを自分のデータセットからReport1.rdlcのマトリックスにドラッグしました。ユーザーがReports.aspxでRunReportButtonをクリックすると、次のエラーが表示されます。「データソースインスタンスがDataSet2 'に指定されていません」コードをデバッグして、このDataSet.Tables [0] .Rows.Count = 3を確認しました。私はまた、reportmodeのためにprocessingmode = localを持っています。どんな助け?本当にありがとう!ここで

は、レポートビューアーを持っている私のReports.aspxマークアップです:

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"> 
ここ

<asp:Label ID="lblMessage" runat="server" Text="Label"></asp:Label> 
<br /> 
<br /> 
<asp:DropDownList ID="DropDownList1" runat="server"> 
    <asp:ListItem>Cardiovascular</asp:ListItem> 
    <asp:ListItem>Weight Lifting</asp:ListItem> 
</asp:DropDownList> 
<asp:ScriptManager ID="ScriptManager1" runat="server"> 
</asp:ScriptManager> 


<asp:Button ID="RunReportButton" runat="server" 
    onclick="RunReportButton_Click1" Text="Run Report" Height="27px" 
    Width="84px" /> 


<rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" 
    Font-Size="8pt" InteractiveDeviceInfos="(Collection)" 
    WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt" 
    Visible="False"> 
    <LocalReport ReportPath="Report1.rdlc"> 

    </LocalReport> 
</rsweb:ReportViewer> 




</asp:Content> 

はReports.aspx.csです:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using Microsoft.ApplicationBlocks.Data; 
using Microsoft.Reporting.WebForms; 
using System.Data.SqlClient; 
using System.Data; 
using System.Data.Common; 
using System.Data.Sql; 
using System.Configuration; 

namespace ExerciseTracker2000 
{ 
public partial class Reports : System.Web.UI.Page 
{ 
    #region Properties 

    public static string ConnectionString { get; set; } 
    public static int personID { get; set; } 
    #endregion 

    #region Variables 

    public int personID = 0; 
    public SqlParameter[] SearchValue = new SqlParameter[2]; 

    #endregion 

    #region Page Events 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     personID = CommonMethods.getLoggedInUser();   
    } 

    protected void RunReportButton_Click1(object sender, EventArgs e) 
    { 
     try 
     { 
      DataSet ds = new DataSet(); 
      string strCategory = ddlCategory.SelectedValue; 
      // strSQL select for orders with no invoices 
      strSQL = "SELECT PersonID, ExerciseDate, Category, Exercise, Duration, Distance, Speed"; 
      strSQL = strSQL + " from dbo.PersonExercise"; 
      strSQL = strSQL + " where PersonID = " + personID + " And Category = '" + strCategory + "'"; 

      using (var connection = new SqlConnection(ConnectionString)) 
      { 
       SqlDataAdapter ad = new SqlDataAdapter(strSQL, connection); 

       ad.Fill(ds, "Table0"); 

      } 


      //ReportViewer1.Visible is set to false in design mode 
      ReportViewer1.Visible = true; 
      SqlConnection thisConnection = new SqlConnection(ConnectionString); 


      /* Associate thisDataSet (now loaded with the stored 
       procedure result) with the ReportViewer datasource */ 
      Microsoft.Reporting.WebForms.ReportDataSource datasource = new 
      Microsoft.Reporting.WebForms.ReportDataSource("DataSetCategories_ShowExercisesByCategory", ds.Tables[0]); 


      ReportViewer1.LocalReport.DataSources.Clear(); 
      ReportViewer1.LocalReport.DataSources.Add(datasource); 

      if (thisDataSet.Tables[0].Rows.Count == 0) 
      { 
       lblMessage.Text = "Sorry, no products under this category!"; 
      } 

      ReportViewer1.LocalReport.Refresh(); 
     } 
     catch (Exception ex) 
     { 
      lblMessage.Text = "Error: " + ex.Message.ToString(); 
     } 
    } 

    #endregion 
} 

} 

答えて

0

あなたのパスです彼は報告します ReportViewer1.LocalReport.Path = "Report1.rdlc";

EDIT:ネヴァーマインドは、私は、XAML

EDIT2でそれを参照してください:あなたはReportViewer1.Reset()を呼び出します。これにより、LocalReportがクリアされます。レポートパスを再度設定する必要があります。

+0

私はReset()メソッドを削除し、次のエラーが表示されます。データソースインスタンスがデータソース 'DataSet2'に指定されていません。どんな助け?ありがとう! – jre247

+0

私は、 "DataSet2"がレポートオブジェクト自体のデータセットの名前であると仮定しています。 ReportViewer1.LocalReport.DataSources.Add(新しいReportDataSource( "DataSet2"、ds))を試してください。 – Jmyster

+0

ありがとう、私はそれが働いた!あなたの助けをありがとう! – jre247

関連する問題