1217834 - Crystal Reports .NET application prompts for parameters although parameters are set at runtime

SAP Knowledge Base Article - Public

1217834 - Crystal Reports .NET application prompts for parameters although parameters are set at runtime

Symptom

  • Setting the CurrentValues for a ParameterField through code using the Crystal Reports .NET SDK.
  • The CrystalReportViewer prompts for new values, even though CurrentValues were set in code.
  • Why is the CrystalReportViewer prompting for new values?

Environment

  • Bundle Versions
    • Crystal Reports for Visual Studio 2005
    • Crystal Reports Basic for Visual Studio 2008
    • Crystal Reports 2010
  • Full Versions
    • Crystal Reports XI R2
    • Crystal Reports 2008

Reproducing the Issue

Using ReportDocument.Refresh()

string filename = "C:\\Reports\\myReport.rpt";
string parameterName = "parameter1";
object parameterValue = "some value";
CrystalDecisions.CrystalReports.Engine.ReportDocument boReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
boReportDocument.Load(filename);
boReportDocument.SetParameterValue(parameterName, parameterValue);
boReportDocument.Refresh();
CrystalReportViewer1.ReportSource = boReportDocument;


Using CrystalReportViewer.RefreshReport()


string filename = "C:\\Reports\\myReport.rpt";
string parameterName = "parameter1";
object parameterValue = "some value";
CrystalDecisions.CrystalReports.Engine.ReportDocument boReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
boReportDocument.Load(filename);
boReportDocument.SetParameterValue(parameterName, parameterValue);
CrystalReportViewer1.ReportSource = boReportDocument;
CrystalReportViewer1.RefreshReport();

Cause

  • This behavior can be caused by the ReportDocument.Refresh() or CrystalReportViewer.RefreshReport() methods.
  • The problem occurs when Refresh() or RefreshReport() are called after the parameter values are set.
  • These methods force the report to be refreshed and can discard the current values for the parameters in the report.

Resolution

Code using ReportDocument.Refresh()

string filename = "C:\\Reports\\myReport.rpt";
string parameterName = "parameter1";
object parameterValue = "some value";
CrystalDecisions.CrystalReports.Engine.ReportDocument boReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
boReportDocument.Load(filename);
boReportDocument.Refresh(); // The Refresh() should be used immediately after Load() to ensure the data is new.
boReportDocument.SetParameterValue(parameterName, parameterValue); 
CrystalReportViewer1.ReportSource = boReportDocument;


Code using CrystalReportViewer.RefeshReport()


string filename = "C:\\Reports\\myReport.rpt";
string parameterName = "parameter1";
object parameterValue = "some value";
CrystalDecisions.CrystalReports.Engine.ReportDocument boReportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
boReportDocument.Load(filename);
boReportDocument.Refresh(); // Use this instead of the CrystalReportViewer.RefreshReport()
boReportDocument.SetParameterValue(parameterName, parameterValue);
CrystalReportViewer1.ReportSource = boReportDocument;
//CrystalReportViewer1.RefreshReport(); The RefreshReport() method shouldn't be used in conjunction with the ReportDocument class.

 

Keywords

DOTNET PROMPTING SET PARAMETER VALUE NET .NET CR.NET VS.NET REFRESHING Crystal Reports for Visual Studio Parameters Prompting , c2016354 RefreshReport ParameterField ParameterFields CurrentValues ParameterValues , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , Problem

Product

Crystal Reports 2008 V1 ; SAP Crystal Reports, developer version for Microsoft Visual Studio ; SAP Crystal Reports, version for Visual Studio .NET 2008