我正在尝试将报告查看器添加到我的WPF应用程序中。我已按照This Site上的步骤操作,但现在我收到此错误:
An error occurred during local report processing. The report definition for report 'ConSegReport' has not been specified. Object reference not set to an instance of an object.
这是我的代码:
private void Reportviewer_Load(object sender, EventArgs e)
{
if (!_IsReportViewerLoaded)
{
Microsoft.Reporting.WinForms.ReportDataSource reportData = new Microsoft.Reporting.WinForms.ReportDataSource();
Consolidated_DBDataSet conSet = new Consolidated_DBDataSet();
conSet.BeginInit();
reportData.Name = "ConSegSet";
reportData.Value = conSet.Cnsldtd_Performance_tbl;
this.reportViewer.LocalReport.DataSources.Add(reportData);
this.reportViewer.LocalReport.ReportEmbeddedResource = "FP Reporting Dashboard.ConSegReport.rdlc";
conSet.EndInit();
Consolidated_DBDataSetTableAdapters.Cnsldtd_Performance_tbl_CLONETableAdapter conAD = new Consolidated_DBDataSetTableAdapters.Cnsldtd_Performance_tbl_CLONETableAdapter();
conAD.ClearBeforeFill = true;
conAD.Fill(conSet.Cnsldtd_Performance_tbl_CLONE);
reportViewer.RefreshReport();
_IsReportViewerLoaded = true;
}
}
我还将.rdlc文件设置为"复制如果更新"输出目录。
答案 0 :(得分:0)
我从未尝试过将嵌入式报告引用到上传到SSRS的报告。
这是我的代码,也许会有所帮助:
IReportServerCredentials irsc = new CustomReportCredentials(rc.report_ssrs_username,
rc.report_ssrs_password, rc.report_ssrs_domain);
ReportViewer1.ServerReport.ReportServerCredentials = irsc;
ReportViewer1.ServerReport.ReportPath = rc.report_ssrs_path;
ReportViewer1.ServerReport.ReportServerUrl = new System.Uri(rc.report_ssrs_url);
SqlConnectionStringBuilder conString = new Database().conBuilder;
List<ReportParameter> parameters = new List<ReportParameter>();
parameters.Add(new ReportParameter("ConString", conString.ConnectionString));
ReportViewer1.ServerReport.SetParameters(parameters);
DataSourceCredentials dsc = new DataSourceCredentials();
dsc.Name = ReportViewer1.ServerReport.GetDataSources()[0].Name;
dsc.UserId = conString.UserID;
dsc.Password = conString.Password;
ReportViewer1.ServerReport.SetDataSourceCredentials(new DataSourceCredentials[] {
dsc });
ReportViewer1.ShowCredentialPrompts = false;
ReportViewer1.ServerReport.Refresh();
如果您对此处的内容有任何疑问,请与我们联系。我们有一个表定义了所有报告,并查询它以动态呈现reportviewer控件。
作为旁注,我将对RDLC文件使用下划线命名约定。如果代码没有正确计算,那可能会使代码绊倒。另外,尝试引用它将是一个完整的路径来验证这不是一个相对路径问题,如果它试图从调试或发布目录引用该文件。
答案 1 :(得分:0)
“ FP Reporting Dashboard.ConSegReport.rdlc”将其更改为“ FP_Reporting_Dashboard.ConSegReport.rdlc”