首页 > 解决方案 > VS2017 中的 Asp.Net 应用程序使用 Crystal Reports 错误“无效的子报表名称”

问题描述

我得到了一个用 CR 8 用 vs2005 编写的旧版 ASP.Net 应用程序。我目前正在运行 vs2017 和 CR 13.0.22。

该应用程序与许多不同的数据交互并显示多个报告,我被要求修改其中的 1 个,它是具有 5 个子报告的父报告。当我最初开始工作时,我在父报表上运行了验证数据库,并被提示使用模式/XML 文件进行连接,这些文件没有进入保存的代码库,现在丢失了。

我重新创建了 6 个连接到数据存储过程的数据集/连接,并重构/重新设计了所有 6 个报告以重新连接到新数据集。

现在,当我运行应用程序时,出现上述错误:无效的子报表名称

这是产生错误的方法:

public void GenerateReport(List<Report> Reports, CrystalReportViewer Viewer)
{
int rptcount;
Report mainreport;

// make sure there is only one main report in the list
rptcount = 0;
mainreport = null;
foreach (Report report in Reports)
{
if (report.IsSubReport == false)
{
rptcount = rptcount + 1;
mainreport = report;
}
}
if (rptcount != 1)
throw new Exception("ReportWriter.GenerateReport: There was more than one main report found in the list of reports. " +
"Only one can be the main report. The other reports have to be subreports.");

// generate the report
checkReportFile(mainreport.ReportName);
document = new ReportDocument();
document.Load(mainreport.ReportName);
document.SetDataSource(mainreport.DataSet);

/* Previously the next line was a call to setReportParameters and the code errored with the Invalid Subreport Name call. I moved that line of code to after the For Each and now the error occurs within the foreach loop on the first iteration. */

// attach sub reports to the main report
foreach (Report report in Reports)
{
if (report.IsSubReport == true)

/* This line throws the error */
document.OpenSubreport(report.ReportName).SetDataSource(report.DataSet);
}
/* This is the previously failing line that I moved to here */
setReportParameters(document, mainreport.ReportParameters);
Viewer.ReportSource = document;
}

我在调试器中运行代码并在错误之前停止执行。然后我在即时窗口中执行了失败行的“document.OpenSubreport(report.ReportName)”部分,这正是引发错误的地方。ReportDocument 类型/对象是 Crystal Decisions 库的一部分,无法在该代码中进一步深入,因此我没有数据来确定究竟是什么失败了。我一遍又一遍地查看所有转换后的子报表,它们在设计器中看起来都很完美。我如何确定这里真正失败的是什么?有没有办法解析 .rpt 文件以查看其中是否有某种遗留垃圾需要删除?如果我找不到答案,我将不得不从头开始......

标签: c#asp.netcrystal-reportsvisual-studio-2017

解决方案


我使用了 Competitive_tech 的建议,但并没有解决我的问题。我最终做的是安装完整的 Crystal Reports(不幸的是 2008 年)应用程序并使用该 IDE 打开报告。IDE 给了我更多信息错误。问题是在父报表和几个子报表的公式字段和分组中存在遗漏的对象替换错误。我还将 setReportParameters 移回原来的调用位置。拥有更好的描述性信息真是太好了,我建议在 Visual Studio CR 设计和独立 CR 设计之间来回切换以隔离错误。


推荐阅读