我已经创建了一个rdlc报告。我的表单上有一个reportViewer。当我尝试加载报告时,我得到:“尚未指定报告'xxxx.rdlc‘的报告定义”。我搞不懂这件事。我有一个datatable,其中包含报告所需的数据。我将这个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连接到报告。我真的看不出有什么问题,我在谷歌上搜索了一下。
任何帮助都将受到高度的感谢。
发布于 2015-12-23 19:53:37
导致此问题的原因有很多,有时只有在将相同的应用程序发布到IIS时才会出现此问题。如果报告文件(*.rdlc)存在于相关位置,但问题仍然存在,您可以尝试以下方法进行修复:
来自LocalReport.ReportEmbeddedResource Property on MSDN的
“…嵌入式报表资源是作为资源存储在调用程序集中的报表定义。如果设置了ReportPath属性,则忽略ReportEmbeddedResource属性。它还会导致使用LoadReportDefinition加载的报告被忽略。“
更改:
reportViewer.LocalReport.ReportPath = Server.MapPath("~/Reporting/YourReportName.rdlc");至:
rw.LocalReport.ReportEmbeddedResource = "YourFullNamespace.Reporting.YourReportName.rdlc";然后从YourReportName.rdlc文件的属性中将Build Action属性更改为Embedded Resource。希望这能帮到你。
发布于 2015-03-25 02:48:58
我得到了相同的错误,但我正在以不同的方式加载我的报告。我遵循了MSDN上的说明。除了他们引用ReportEmbeddedResource I的地方,取而代之的是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是
<Page x:Class="MyProject.Views.ReportViewer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xm![enter image description here][2]lns:rv="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="ReportViewer">
<Grid>
<WindowsFormsHost>
<rv:ReportViewer x:Name="_reportViewer"/>
</WindowsFormsHost>
</Grid>
</Page>另外:
../../Myreport.rdlc这样的语法,则可能不会复制到输出目录。
ReportViewer dll。当我转到引用>添加引用...> 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‘。
发布于 2013-05-03 00:30:09
您在何处将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();
}它似乎对我很有效。
https://stackoverflow.com/questions/8505700
复制相似问题