繁体   English   中英

VS2017中使用Crystal Reports错误'Invalid Subreport Name'的Asp.Net应用

[英]Asp.Net app in VS2017 using Crystal Reports error 'Invalid Subreport Name'

我已经获得了用vs2005和CR 8编写的遗留ASP.Net应用程序。我目前正在运行vs2017和CR 13.0.22。

该应用程序与许多不同的数据进行交互并显示多个报告,我被要求修改其中的一个,即具有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文件,以查看其中是否需要删除某种旧式垃圾? 如果找不到答案,我将不得不从头开始...

建议您不要使用OpenSubReport,而是在主报表上使用Subreports集合,测试是否为null。 然后,您可以告诉调用者他们请求的子报表名称不正确(如果该名称不存在)。

就像是

foreach (Report report in Reports)
{
    if (!report.IsSubReport)
    {
        continue;
    }
    var subReport = document.SubReports[report.ReportName];
    if (subReport == null) {
        throw new Exception($"Subreport {report.ReportName} not found");
    }
    subReport.SetDataSource(report.DataSet);
}

使用SubReports集合还可以让您确切地检查加载了哪些子报表。 完全可能会有细微的错别字甚至大小写不同,这可能会有所不同。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM