C# 在reportViewer中的.rdlc报告之间切换
我创建了4个报告,其中包含数据库中4个表的信息。在我的应用程序中,我有一个C# 在reportViewer中的.rdlc报告之间切换,c#,reporting,rdlc,C#,Reporting,Rdlc,我创建了4个报告,其中包含数据库中4个表的信息。在我的应用程序中,我有一个menuStrip,其中包含名为this reports的项。如何使我的应用程序reportViewer显示在菜单中选择的报告 我尝试了以下代码: ReportDataSource RDS = new ReportDataSource(); RDS.Value = this.KontrolorKazneBindingSource; reportViewer1.LocalReport.DataSources.Add(RDS)
menuStrip
,其中包含名为this reports的项。如何使我的应用程序reportViewer
显示在菜单中选择的报告
我尝试了以下代码:
ReportDataSource RDS = new ReportDataSource();
RDS.Value = this.KontrolorKazneBindingSource;
reportViewer1.LocalReport.DataSources.Add(RDS);
reportViewer1.LocalReport.ReportPath = @"C:\Users\User\documents\visual studio 2010\Projects\Kontrolor\Kontrolor\KontrolorKazne.rdlc";
reportViewer1.RefreshReport();
但是我得到了一个错误:数据源实例没有被提供给数据源
你能告诉我我做错了什么以及如何解决这个问题吗?首先,我认为你应该调用reportViewer1.Reset()
来告诉ReportViewer为你创建一个新的LocalReport实例。()
之后,您可以为ReportDataSource命名:
ReportDataSource RDS = new ReportDataSource("YourReportDataSourceName");
YourReportDataSourceName
是您在报表数据窗格的报表设计器中设置的名称 首先,我认为您应该调用reportViewer1.Reset()
来告诉ReportViewer为您创建一个新的LocalReport实例。()
ReportViewer1.Reset();
Microsoft.Reporting.WebForms.ReportDataSource reportDataSouce = new Microsoft.Reporting.WebForms.ReportDataSource();
if (DDAllRepotts.SelectedIndex == 1) {
reportDataSouce.DataSourceId = "ObjectDataSourceALL";
reportDataSouce.Name = "DataSetALL";
ReportViewer1.LocalReport.DataSources.Add(reportDataSouce);
ReportViewer1.LocalReport.ReportPath = "Report7.rdlc";
ReportViewer1.LocalReport.Refresh();
}
else if (DDAllRepotts.SelectedIndex == 2) {
reportDataSouce.DataSourceId = "ObjectDataSourceVoltage";
reportDataSouce.Name = "DatasetForVoltage";
ReportViewer1.LocalReport.DataSources.Add(reportDataSouce);
ReportViewer1.LocalReport.ReportPath = "Reports/ReportVoltage.rdlc";
ObjectDataSourceVoltage.DataBind();
this.ReportViewer1.LocalReport.Refresh();
}
之后,您可以为ReportDataSource命名:
ReportDataSource RDS = new ReportDataSource("YourReportDataSourceName");
YourReportDataSourceName
是您在报表数据窗格的报表设计器中设置的名称 是的,我以类似的方式工作:ReportDataSource RDC=newreportdatasource();RDC.Name=“KontrolorKazneIzvjestaj”;RDC.Value=this.kontrolkaznebindingsource;this.reportViewer1.LocalReport.DataSources.Add(RDC);this.reportViewer1.LocalReport.ReportEmbeddedResource=“Kontrolor.kontrolkazneizvjestaj.rdlc”;this.reportViewer1.RefreshReport()代码>我不需要调用重置方法。无论如何,谢谢是的,我以类似的方式工作:ReportDataSource RDC=newreportdatasource();RDC.Name=“KontrolorKazneIzvjestaj”;RDC.Value=this.kontrolkaznebindingsource;this.reportViewer1.LocalReport.DataSources.Add(RDC);this.reportViewer1.LocalReport.ReportEmbeddedResource=“Kontrolor.kontrolkazneizvjestaj.rdlc”;this.reportViewer1.RefreshReport()代码>我不需要调用重置方法。无论如何谢谢你
ReportViewer1.Reset();
Microsoft.Reporting.WebForms.ReportDataSource reportDataSouce = new Microsoft.Reporting.WebForms.ReportDataSource();
if (DDAllRepotts.SelectedIndex == 1) {
reportDataSouce.DataSourceId = "ObjectDataSourceALL";
reportDataSouce.Name = "DataSetALL";
ReportViewer1.LocalReport.DataSources.Add(reportDataSouce);
ReportViewer1.LocalReport.ReportPath = "Report7.rdlc";
ReportViewer1.LocalReport.Refresh();
}
else if (DDAllRepotts.SelectedIndex == 2) {
reportDataSouce.DataSourceId = "ObjectDataSourceVoltage";
reportDataSouce.Name = "DatasetForVoltage";
ReportViewer1.LocalReport.DataSources.Add(reportDataSouce);
ReportViewer1.LocalReport.ReportPath = "Reports/ReportVoltage.rdlc";
ObjectDataSourceVoltage.DataBind();
this.ReportViewer1.LocalReport.Refresh();
}