編輯:我做到了,所以我正在執行一條sql語句而不是存儲過程,僅用於調試。我現在有一個錯誤:沒有爲數據源'DataSet2'提供數據源實例。我也擺脫了ReportViewer1.Reset();Reportviewer無法正常顯示報告
我想弄清楚爲什麼我的reportviewer沒有顯示像它應該在用戶點擊Reports.aspx上的按鈕「RunReportButton」後的報告。我有一個sql語句有2個參數:@PersonID和@Category。這個sql語句搜索PersonExercise表中所有具有PersonID = @PersonID和@Category = Category的記錄。我執行一個基於這個sql語句的數據集,然後將其傳遞到我的reports.aspx後面的代碼中的reportDataSource。
然後我創建Report1.rdlc並將其鏈接到我的數據集dsCardio。我將ExerciseDate,Distance,Speed從我的數據集拖到Report1.rdlc上的矩陣中。當用戶單擊Reports.aspx上的RunReportButton時,出現以下錯誤:「數據源實例尚未提供給數據源'DataSet2'」。我調試了我的代碼,我看到了thisDataSet.Tables [0] .Rows.Count = 3,它應該。對於reportviewer,我也有processingmode = local。任何幫助?非常感謝!
這裏是我的Reports.aspx標記具有的ReportViewer:
<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
}
}
我擺脫了Reset()方法,現在我得到以下錯誤:沒有爲數據源'DataSet2'提供數據源實例。任何幫助?謝謝! – jre247 2012-03-07 14:53:28
我假設「DataSet2」是報表對象本身中的數據集的名稱。嘗試ReportViewer1.LocalReport.DataSources.Add(新的ReportDataSource(「DataSet2」,ds)); – Jmyster 2012-03-07 18:32:34
謝謝,我懂了!非常感謝你的幫助! – jre247 2012-03-07 19:11:28