在VS2012后的版本中做数据报表时,提示尚未指定报表“Report1”的报表定义
有一群的朋友在用VS2012做数据报表时,老是提示
- 本地报表处理期间出错。
- 尚未指定报表“Report1”的报表定义
- 未将对象引用设置到对象的实例。
我看了一下,步骤没错,我用VS2010做了一下,一切OK,没问题,但用VS2013做时,
就提示这错误
后仔细看了一下设计生成的源码,嘿,还真有区别,在VS2012与VS2013中,
ReportViewer生成的代码在引用报表数据时,使用的是ReportEmbeddedResource属性
1 2 3 4 5 | <LocalReport ReportEmbeddedResource= "WebApplication1.Report1.rdlc" > <DataSources> <rsweb:ReportDataSource DataSourceId= "ObjectDataSource1" Name= "DataSet1" /> </DataSources> </LocalReport> |
在VS2010的版本中使用的是ReportPath
1 2 3 4 5 | <LocalReport ReportPath= "Report1.rdlc" > <DataSources> <rsweb:ReportDataSource DataSourceId= "ObjectDataSource1" Name= "DataSet1" /> </DataSources> </LocalReport> |
而ReportPath与ReportEmbeddedResource的区别是:
ReportPath是获取或设置本地报表的本地文件系统路径,
设置 ReportPath 属性将导致 ReportViewer 控件从文件系统自动加载所需的任何子报表。
设置此属性将导致ReportEmbeddedResource 属性的值被忽略
ReportEmbeddedResource是嵌入报表资源是已经作为资源存储在调用程序集中的报表定义。
因为要手动修改使用ReportPath,就能解决这问题
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步