在VS2012后的版本中做数据报表时,提示尚未指定报表“Report1”的报表定义

有一群的朋友在用VS2012做数据报表时,老是提示

  • 本地报表处理期间出错。
    • 尚未指定报表“Report1”的报表定义
      • 未将对象引用设置到对象的实例。

我看了一下,步骤没错,我用VS2010做了一下,一切OK,没问题,但用VS2013做时,

就提示这错误

后仔细看了一下设计生成的源码,嘿,还真有区别,在VS2012与VS2013中,

ReportViewer生成的代码在引用报表数据时,使用的是ReportEmbeddedResource属性

<LocalReport  ReportEmbeddedResource="WebApplication1.Report1.rdlc">
                <DataSources>
                    <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
                </DataSources>
            </LocalReport>

 在VS2010的版本中使用的是ReportPath

 <LocalReport  ReportPath="Report1.rdlc">
                <DataSources>
                    <rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet1" />
                </DataSources>
            </LocalReport>

而ReportPath与ReportEmbeddedResource的区别是:

ReportPath是获取或设置本地报表的本地文件系统路径,

设置 ReportPath 属性将导致 ReportViewer 控件从文件系统自动加载所需的任何子报表。

设置此属性将导致ReportEmbeddedResource 属性的值被忽略

ReportEmbeddedResource是嵌入报表资源是已经作为资源存储在调用程序集中的报表定义。

因为要手动修改使用ReportPath,就能解决这问题

 

posted @ 2014-11-12 21:00  刘继先  阅读(8747)  评论(1编辑  收藏  举报