簡體   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