2013-12-10 57 views
0

使用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); 
      } 

回答

0

您可以嘗試在您的Page_Unload事件中使用它。

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

這應該在頁面卸載時擺脫報告,並且當用戶回到頁面時您將開始新鮮。 在這篇文章中有一個很好的例子here

+0

很抱歉,在所有加載後,Page_Unload事件都會觸發;因此,它將在可以查看之前關閉/處理報告。 –

+0

我剛剛看到您添加到問題中的代碼。你爲什麼評論第2至第4行?這應該照顧它 - >清除Page_Load上的所有內容,然後加載報告。 –

+0

我註釋掉的行不起作用,但我將它們留在那裏,所以我不再嘗試它們。 –

0

我找到了解決方案! --------不

在我的問題之前,所有的代碼添加此線之上:

CrystalReportViewer1.ParameterFieldInfo.Clear(); 

然後加載的文件名等等.......

+0

好,我收回。經過一些測試後發現上面的新行會阻止打印報告。很奇怪。雖然我會找到解決方案.... –