c# - 报告和reportviewer控件不在同一个项目中如何访问报告
问题描述
我有reportviewer
winforms项目。在第二个项目中,我得到了报告及其数据源。如何正确访问来自winform
的项目的报告?
到目前为止,我在 win forms 项目中所做的事情:
var pathToReport= @"C:\Users\Term\Report Project1\Raport1.rdl";
this.reportViewer1.LocalReport.ReportPath = pathToReport;
this.reportViewer1.RefreshReport();
一旦我运行这个我得到错误:
a data source instance has not been suplied for the data soruce 'DataSet1'
在报告所在的项目中有该数据集,因此我可以以某种方式指向它吗?看:
我找到了ReportDataSource()
,但我没有看到任何选项可以为位于第二个项目中的数据集提供路径。
解决方案
您可以尝试从第二个项目的 dll 文件加载报告定义,然后将数据源添加到报告定义中,为此,您需要对第二个项目的引用:
System.Reflection.Assembly Assembly = System.Reflection.Assembly.LoadFrom ("SecondProject.dll" );
System.IO.Stream Stream = Assembly.GetManifestResourceStream ( "SecondProject.Report1.rdlc" );
this.reportViewer1.LocalReport.LoadReportDefinition ( Stream );
this.reportViewer1.LocalReport.DataSources.Clear ( );
this.reportViewer1.LocalReport.DataSources.Add ( new ReportDataSource ( "DataSet1" , SecondProject.MyDataSource ) );
推荐阅读
- python - 鱼壳选项卡完成程序简短描述 - 如何?
- react-native - 在 build\kotlin\sessions 检测到多个 Kotlin 守护进程会话 - React-Native
- c++ - 添加 boost 头文件会导致编译时错误
- ios - 如何使用 Getstream Rest API 在 Postman 中获取响应?
- python - 删除关键字周围的所有文本,包括空格和括号
- reactjs - 在firebase get函数中没有调用任何函数
- git - 尽管提供了所需的路径,如何修复“无法在您的路径中找到 Git”错误
- flutter - Flutter 获取库 - 未处理的异常:NoSuchMethodError:在 null 上调用了 getter 'overlay'。E/颤振(29207):接收器:空
- javascript - 检查 redux 存储中的数据更新
- python - 需要找到'$word;' 字符串中的模式