我试图弄清楚为什么我的报告查看器在用户点击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
}
}
答案 0 :(得分:0)
您的报告路径在哪里 ReportViewer1.LocalReport.Path =“Report1.rdlc”;
编辑:没关系,我在XAML中看到它
EDIT2:你调用ReportViewer1.Reset();这是清除LocalReport。您必须再次设置报告路径。