【发布时间】:2012-03-06 20:43:52
【问题描述】:
编辑:我做到了,所以我正在执行一个 sql 语句而不是存储过程,只是为了调试。我现在有一个错误:尚未为数据源“DataSet2”提供数据源实例。我也摆脱了 ReportViewer1.Reset();
我试图弄清楚为什么在用户单击 Reports.aspx 上的“RunReportButton”按钮后,我的报告查看器没有显示应有的报告。我有一个有 2 个参数的 sql 语句:@PersonID 和 @Category。此 sql 语句搜索 PersonExercise 表中 PersonID = @PersonID 和 @Category = Category 的所有记录。我根据这个 sql 语句执行一个数据集,然后在我的 reports.aspx 后面的代码中将它传递给我的 reportDataSource。
然后我创建了 Report1.rdlc 并将其链接到我的数据集 dsCardio。我将练习日期、距离、速度从我的数据集中拖到 Report1.rdlc 上的矩阵上。当用户单击 Reports.aspx 上的 RunReportButton 时,我收到以下错误:“尚未为数据源 'DataSet2' 提供数据源实例”。我调试了我的代码,我看到 thisDataSet.Tables[0].Rows.Count = 3,它应该。对于reportviewer,我也有处理模式=本地。有什么帮助吗?非常感谢!
这是我的带有报告查看器的 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
}
}
【问题讨论】:
标签: reportviewer