Showing results for 
Search instead for 
Did you mean: 

Best way to reliably set report parameters?

Former Member
0 Kudos

We use a central controller for all of our 350 reports. The reports may be simple, or they may be complex and feature multiple subreports. The parameters differ by report. However, we have some common parameters that may or may not be in most reports. The calling application does not have to set them as the controller will set them automatically. My question is simple, what is the best way to reliably set parameter values in a generic way for main reports and subreports?

There's numerous ways to accomplish this, but all seem to have faults...

// imagine we have these objects

ReportDocument report;

string name;

object value;

// Can set this way for the report if this is a main report.

// 1. This throws an exception if the parameter name does not exist.

// 2. Seems to support subreport parameters.

report.SetParameterValue(name, value);

// Can set this way for the report, too.

// 1. This throws an exception if the parameter name does not exist.

// 2. This throws an exception if the parameter is linked.

// 3. I believe this sets parameters in subreports.

ParameterFieldDefinition parameter = report.DataDefinition.ParameterFields[paramName];

ParameterValues paramValues = parameter.CurrentValues;

ParameterDiscreteValue newValue = new ParameterDiscreteValue();

newValue.Value = paramValue;



// Can set this way, too.

// 1. Does not throw an exception.

// 2. Cannot be used for subreports!

// 3. Cannot set subreport values!

ParameterField parameter = report.ParameterFields[paramName];

if (parameter != null)


ParameterDiscreteValue pdv = new ParameterDiscreteValue();

pdv.Value = paramValue;




To me, report.SetParameterValue should be the chosen way to set the parameter. However, it should never throw an exception. If a parameter does not exist in the report, it should ignore it. Am I crazy? What's the correct answer? Thanks!


P.S. There's no great way to identify parameters that are in an entire RPT (main report and subreports). I have to write this code to find out. All other options throw exceptions or don't consistently return results if there's a subreport:

private bool ReportContainsParameter(ref ReportDocument report, string name)


foreach (ParameterFieldDefinition parameter in report.DataDefinition.ParameterFields)


if (String.Compare(parameter.Name, name, StringComparison.OrdinalIgnoreCase) == 0)


return true;



return false;


Accepted Solutions (1)

Accepted Solutions (1)

Active Contributor
0 Kudos

I don't know what version of CR you are using. What CR service Packs you are using. What version of .NET you are using.

All good info to have...

Parameters are complicated not trivial so there is no generic or simple way of providing code and saying; there this will work.

Your best bet is to

1) Go through the Developer help files for your version of CR

2) Look at sample apps:

3) Search for KBases, blogs, articles, etc. (use the search box in the top right corner of this web page)

4) Download the [Crystal Reports for Visual Studio 2005 Walkthroughs|] (will apply to all versions of CR and .NET).

5) Google, you'll find all kinds of info. For example:

6) When you run into a specific issue, create a forum thread specific to that issue, specifying as much info as possible. See [Rules of Engagement|]

Step 2 Asking Your Question; Provide Enough Information

and [What do I need to do to get the fastest issue resolution?|]

7) For critical issues, consider creating a phone case here:


Follow us on Twitter

Got Enhancement ideas? Try the [SAP Idea Place|]

Answers (0)