ASP.NET MVC5中的ReportViewer报告不显示数据

时间:2017-09-12 01:38:12

标签: c# asp.net asp.net-mvc reporting-services

我正在使用ASP.NET MVC5应用程序中的第一个ReportViewer报告,而且我在报告上显示数据时遇到问题。我在这个网站上搜索并发现了类似的问题,但他们的解决方案似乎都没有帮助我解决我的问题。

最初,我收到以下错误消息: 尚未为数据源“DataSet1”

提供数据源实例

作为回应,我将数据集名称从“ReportDataSet”更改为“DataSet1”,但我没有在任何地方使用“Dataset1”。我认为这是使用报表向导创建数据集时数据集的默认名称,但我当时将其重命名为“ReportDataSet”。

在添加到ReportViewer1.LocalReport.DataSources之前,我已检查过ReportDataSource的内容,并且其中包含数据。

我相信我已经接近显示报告了,但是对于之前可能使用ReportViewer创建报告的人来说可能缺少一些明显的东西,但作为第一次使用,我想我已经错过了。如果有人能指出我所缺少的东西,我将非常感激。谢谢。

对于rdlc报告,我使用报告向导创建Report1.rdlc,它具有以下数据集属性: 名称:ReportDataSet 数据源:ReportDataSet 可用数据集:tblCrosswalk

ReportViewer.aspx.cs:

protected void Page_Load(object sender, EventArgs e) // This is called by OnLoad
{
    if (!IsPostBack)
    {
        ReportViewer1.ProcessingMode = ProcessingMode.Local;
        ReportViewer1.LocalReport.ReportPath = Server.MapPath("Report1.rdlc");
        CWEntities db = new CWEntities();
        // ReportDataSource dataSource = new ReportDataSource("ReportDataSet", (from tblCrosswalk in db.tblCrosswalks.Take(10) select tblCrosswalk));
        ReportDataSource dataSource = new ReportDataSource("DataSet1", (from tblCrosswalk in db.tblCrosswalks.Take(10) select tblCrosswalk)); 
        // I have changed “ReportDataSet” to “DataSet1” in response to error message, 
        // but I’m not using “DataSet1” anywhere. I think this was the default name of 
        // the Dataset when I was creating the Dataset using Report Wizard, but I 
        // renamed this to “ReportDataSet”
        ReportViewer1.LocalReport.DataSources.Clear();
        ReportViewer1.LocalReport.DataSources.Add(dataSource);
        ReportViewer1.LocalReport.Refresh();
        // Report is not showing any data, but there is data in the dataSource!
    }
}

reportviewer.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReportViewer.aspx.cs" Inherits="CW.Reports.ReportViewer" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=12.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" AsyncPostBackTimeout="600" runat="server"></asp:ScriptManager>
        <div>
            <rsweb:ReportViewer ID="ReportViewer1" runat="server" Height="800px" Width="1025px" ShowParameterPrompts="False" ShowToolBar="True"  ShowCredentialPrompts="False" ProcessingMode="Local" AsyncRendering="false" >
            </rsweb:ReportViewer>    
        </div>
    </form>
</body>
</html>

reportcontroller.cs:

public class ReportController : Controller
{
    // GET: Reports
    // private CWEntities db = new CWEntities();
    public ActionResult Index()
    {
        return View();
    }
}

index.cshtml:

<h2>Index</h2>

<html>
    <head>
        <title>=Index</title>
    </head>
    <body>
        <h4>Crosswalk</h4>
        <iframe id="=" Reports" src="~/Reports/ReportViewer.aspx" width="950" height="460"></iframe>
    </body>
</html>

Report1.rdlc:

<AutoRefresh>0</AutoRefresh>
 <DataSources>
 <DataSource Name="ReportDataSet">
  <ConnectionProperties>
    <DataProvider>System.Data.DataSet</DataProvider>
    <ConnectString>/* Local Connection */</ConnectString>
  </ConnectionProperties>
  <rd:DataSourceID>5ae1078e-19a3-46ae-9df6-7e6149fc88b9</rd:DataSourceID>
</DataSource>

<DataSets>
<DataSet Name="DataSet1">
  <Query>
    <DataSourceName>ReportDataSet</DataSourceName>
    <CommandText>/* Local Query */</CommandText>
  </Query>
  <Fields>
    <Field Name="crosswalkID">
      <DataField>crosswalkID</DataField>
      <rd:TypeName>System.Int32</rd:TypeName>
    </Field>
    <Field Name="IMPCreateDate">
      <DataField>IMPCreateDate</DataField>
      <rd:TypeName>System.DateTime</rd:TypeName>
    </Field>
    <Field Name="stripedDate">
      <DataField>stripedDate</DataField>
      <rd:TypeName>System.DateTime</rd:TypeName>
    </Field>
    <Field Name="jurisdiction">
      <DataField>jurisdiction</DataField>
      <rd:TypeName>System.String</rd:TypeName>
    </Field>
    <Field Name="school">
      <DataField>school</DataField>
      <rd:TypeName>System.String</rd:TypeName>
    </Field>
    <Field Name="signalNumberFlag">
      <DataField>signalNumberFlag</DataField>
      <rd:TypeName>System.Boolean</rd:TypeName>
    </Field>
    <Field Name="updateDate">
      <DataField>updateDate</DataField>
      <rd:TypeName>System.DateTime</rd:TypeName>
    </Field>
    <Field Name="userID">
      <DataField>userID</DataField>
      <rd:TypeName>System.String</rd:TypeName>
    </Field>
    <Field Name="comment">
      <DataField>comment</DataField>
      <rd:TypeName>System.String</rd:TypeName>
    </Field>
  </Fields>
  <rd:DataSetInfo>
    <rd:DataSetName>ReportDataSet</rd:DataSetName>
    <rd:SchemaPath>C:\CW\ReportDataSet.xsd</rd:SchemaPath>
    <rd:TableName>tblCrosswalk</rd:TableName>
    <rd:TableAdapterFillMethod>Fill</rd:TableAdapterFillMethod>
    <rd:TableAdapterGetDataMethod>GetData</rd:TableAdapterGetDataMethod>
    <rd:TableAdapterName>tblCrosswalkTableAdapter</rd:TableAdapterName>
  </rd:DataSetInfo>
</DataSet>

<rd:ReportUnitType>Inch</rd:ReportUnitType>
<rd:ReportID>a27effaf-e67b-4589-af00-be1915741a74</rd:ReportID>

0 个答案:

没有答案