【问题标题】:Clear Crystal Report Parameter清除水晶报表参数
【发布时间】:2013-12-10 16:18:14
【问题描述】:

使用 Visual Studio 2010 和 Crystal Reports 13.0。

对于报表,提示用户输入值。然后生成的报告没有问题。

如果用户离开 report.aspx 页面并返回运行另一个报表,则不会显示提示,并且上次运行的报表仍然存在,并带有用户的原始值。

四处寻找解决方案,只找到了两个没有用:

 //After the report loads
 CrystalReportSource1.ReportDocument.ParameterFields.Clear();

错误:

您不能使用此方法添加、删除或修改参数字段。请直接修改报告。

直接修改报表:

右键单击水晶报表的正文 然后转到:

设计 -> 默认设置.. ->报告

勾选复选框

加载报告时丢弃保存的数据。

这不起作用。之前的报告仍然存在。

所以,我现在想请教一下如何解决这个问题。

一如既往,欢迎提出任何建议。

谢谢

编辑:

这是报告页面的代码。许多报告使用此页面....

            CrystalReportSource1.Report.FileName = "reports\\" + fileName + ".rpt";

            //CrystalReportSource1.Report.Parameters.Clear();
            //CrystalReportSource1.Report = null;
            //CrystalReportSource1.Report.Refresh();

            if (!string.IsNullOrEmpty(Request.QueryString["item"]))
            {
                String Item = Request.QueryString["item"];
                CrystalDecisions.Web.Parameter temp = new CrystalDecisions.Web.Parameter();
                temp.Name = "Item";
                temp.DefaultValue = Item;
                CrystalReportSource1.Report.Parameters.Add(temp);
            }

            SqlConnectionStringBuilder settings = new SqlConnectionStringBuilder(MyConnectionString);

            _crReportDocument = CrystalReportSource1.ReportDocument;
            _crConnectionInfo.ServerName = settings.DataSource;
            _crConnectionInfo.DatabaseName = settings.InitialCatalog;
            _crConnectionInfo.UserID = settings.UserID;
            _crConnectionInfo.Password = settings.Password;

            //Get the table information from the report
            _crDatabase = _crReportDocument.Database;
            _crTables = _crDatabase.Tables;

            //Loop through all tables in the report and apply the
            //connection information for each table.
            for (int i = 0; i < _crTables.Count; i++)
            {
                _crTable = _crTables[i];
                _crTableLogOnInfo = _crTable.LogOnInfo;
                _crTableLogOnInfo.ConnectionInfo = _crConnectionInfo;
                _crTable.ApplyLogOnInfo(_crTableLogOnInfo);
            }

【问题讨论】:

    标签: c# asp.net crystal-reports


    【解决方案1】:

    您可以尝试在 Page_Unload 事件中使用它。

    Report.Close();
    Report.Dispose();
    

    这应该会在页面卸载时摆脱报告,并且当用户返回页面时您将重新开始。 这篇文章中有一个很好的例子here

    【讨论】:

    • 抱歉,Page_Unload 事件在所有内容加载后触发;因此,它会在查看之前关闭/处理报告。
    • 我刚刚看到您添加到问题中的代码。为什么要注释掉第 2 到 4 行?这应该会处理它 -> 清除 Page_Load 上的所有内容,然后加载报告。
    • 我注释掉的行不起作用,但我把它们留在那里,所以我不再尝试了。
    • 您是否尝试将我的答案中的代码放在 Page_Load 事件的开头?您注释掉的三行也必须放在 Page_Load 事件的最开始,以便它们首先被执行。
    【解决方案2】:

    我找到了解决办法!!!! -------- 不是

    在我上面的问题中的所有代码之前添加这一行:

     CrystalReportViewer1.ParameterFieldInfo.Clear();
    

    然后加载文件名等等......

    【讨论】:

    • 好吧,我收回了。经过一些测试,结果发现上面的新行将阻止打印报告。很奇怪。不过我会找到解决方案的......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多