我的RDLC报告中没有指定“报告的报告定义’xxxx.rdlc’”

我创建了一个rdlc报告。 我的表单上有一个reportViewer。 当我尝试加载报告时,我得到:“报告’xxxx.rdlc’的报告定义尚未指定”。 我无法弄清楚这一点。 我有一个数据表,其中包含报告所需的数据。 我把这个dataTable加载到我的数据库,然后加载到一个名为“FinalReport”的表中。 (我之所以这样做,是因为rdlc需要某种dataSource。)我的报告中有一个表(table1)。 这是我的代码(在我的表单中,报表查看器所在的位置):

this.finalDataReportTableAdapter.Fill(this.nehasitDataSet.FinalDataReport); localReport.ReportEmbeddedResource = @"Resources\VisibleAssets.rdlc"; //I'm not so sure about the following line, but it's the only line that prevented me from getting an error ("no reportdefinition defined" using (StreamReader rdlcSR = new StreamReader(@"Resources\VisibleAssets.rdlc")) { localReport.LoadReportDefinition(rdlcSR); localReport.Refresh(); } this.reportViewer.RefreshReport(); 

我还将报告连接到dataTable,将reportViewer连接到报告。 我真的看不出问题,我搜索谷歌。

任何帮助将受到高度赞赏。

我得到了同样的错误,但我以不同的方式加载我的报告。 我按照MSDN上的说明进行操作。 除非他们引用ReportEmbeddedResource I, ReportEmbeddedResource使用ReportPath 。 当我进行更改时,我的报告会加载。

 public partial class ReportViewer : Page { private bool _isReportViewerLoaded; public ReportViewer() { InitializeComponent(); _reportViewer.Load += _reportViewer_Load; } void _reportViewer_Load(object sender, EventArgs e) { if (!_isReportViewerLoaded) { Microsoft.Reporting.WinForms.ReportDataSource reportDataSource1 = new Microsoft.Reporting.WinForms.ReportDataSource(); BossbergDataset dataset = DataAccessConstants.myDataset; dataset.BeginInit(); reportDataSource1.Name = "DataSet1"; //Name of the report dataset in our .RDLC file reportDataSource1.Value = dataset.Table1; this._reportViewer.LocalReport.DataSources.Add(reportDataSource1); //My testReport.Rdlc has the [Copy to Output Directory] set to [Copy Always] this._reportViewer.LocalReport.ReportPath = @"Reports/TestReport.rdlc"; dataset.EndInit(); DataAccessConstants.Table1Adapter.Fill(dataset.Table1); _reportViewer.RefreshReport(); _isReportViewerLoaded = true; } } } 

我的XAML就是

        

也:

  • 确保将报告文件复制到输出目录。 如果您使用的语法如../../Myreport.rdlc ,则可能无法复制到输出目录。 输出目录要求

  • 确保您引用了正确版本的ReportViewer DLL。 当我转到References> Add Reference …> Assemblies> Extensions并找到报表查看器dll时它是旧版本。 我需要明确导航到

    C:\Program Files (x86)\Microsoft Visual Studio 12.0\ReportViewer\Microsoft.ReportViewer.WinForms.dll

    找到最新的。 如果你弄错了,你会得到一个错误

    报告定义无效。 详细信息:报表定义具有无效的目标命名空间“ http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition ”,无法升级。

导致此问题的原因有一些,有时仅在将相同的应用程序发布到IIS时才会出现问题。 如果报告文件(* .rdlc)存在于相关位置,问题仍然存在,您可以尝试以下方法来修复它:

来自 MSDN上的LocalReport.ReportEmbeddedResource属性
“…嵌入式报告资源是一种报告定义,已作为资源存储在调用程序集中。 如果已设置ReportPath属性,则忽略ReportEmbeddedResource属性。 它还会导致加载LoadReportDefinition的报告被忽略。“

更改:

 reportViewer.LocalReport.ReportPath = Server.MapPath("~/Reporting/YourReportName.rdlc"); 

至:

 rw.LocalReport.ReportEmbeddedResource = "YourFullNamespace.Reporting.YourReportName.rdlc"; 

然后从YourReportName.rdlc文件的属性将Build Action属性更改为Embedded Resource 。 希望这可以帮助…

在哪里将localReport与reportViewer相关联? 代替:

  using (StreamReader rdlcSR = new StreamReader(@"Resources\VisibleAssets.rdlc")) { localReport.LoadReportDefinition(rdlcSR); localReport.Refresh(); } 

我用了:

  using (StreamReader rdlcSR = new StreamReader(@"Resources\VisibleAssets.rdlc")) { reportViewer1.LocalReport.LoadReportDefinition(rdlcSR); reportViewer1.LocalReport.Refresh(); } 

它似乎对我有用。

完全像你说的那样,因为rdlc需要某种dataSource :)这是一个棘手的问题在Report viewer中解决它我写了一个方法,它将直接从Datatable绑定报表:

 private void GenerateReportDirect(ReportViewer reportViewer, string datasource, DataTable dt, string reportpath) { reportViewer.LocalReport.ReportPath = reportpath; ReportDataSource repds = new ReportDataSource(datasource, dt); reportViewer.LocalReport.DataSources.Clear(); reportViewer.LocalReport.DataSources.Add(repds); reportViewer.LocalReport.Refresh(); } 

要实现此方法,您必须指定将数据集表适配器的字符串作为名称,但我们的报告将从数据表中绑定数据(我们将在报表查看器上作弊:))

 private void BindReport(DataTable dt) { string reportPath = Server.MapPath("StudentBus.rdlc"); GenerateReportDirect(ReportViewer1, "StudentDataSet_usp_RPT_StudentBus", dt, reportPath); } 

我希望这个能帮上忙 :) 。

我的一个报告发生了同样的问题。 这是一份本地嵌入式报告。

  1. 我没有设置ReportEmbeddedResource属性。
  2. 当我设置了ReportEmbeddedResource property ,它仍然给出了错误,因为报告名称具有错误的大小写 – myApp.reports.rptMyJobstatus.rdlc而不是myApp.reports.rptMyJobStatus.rdlc

因此,您需要检查这两个条件。