如何解决Report和ReportViewer控件不在同一个项目中,我如何访问报告
我在Winforms项目中有reportviewer
。在第二个项目中,我得到了报告及其数据源。
如何从winform
的项目中正确访问报告?
到目前为止,我在赢表格项目中所做的事情:
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 ) );
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。