Skip to Content
0
Former Member
Jan 08, 2009 at 08:21 PM

Why are my parameter values not setting in report?

15 Views

G'day,

Like many others I am a developer who is new to crystal reports. I have researched a lot for setting report parameters and although my code seem to be working when I open the report through code I'm always asked to re-enter the parameter values.

Here is my code:

behind button event

-


PersonalAttendance myReport = new PersonalAttendance();
ReportUtility ru = new ReportUtility();
ru.SetReportParameter(myReport, "reportName","the title");
myReport.Refresh();
myReport.SetDataSource([a data source]);
ReportViewer.ReportSource = myReport;

-


method behind custom class "ReportUtility()"

-


public void SetReportParameter(ReportClass rc, string FieldName, object parameterValue)
{
//Get the collection of parameters from the report
crParameterFieldDefinitions = rc.DataDefinition.ParameterFields;

//Access the specified parameter from the collection
crParameterFieldDefinition = crParameterFieldDefinitions[FieldName];
			
//Get the current values from the parameter field.  At this point
//there are zero values set.
crParameterValues = crParameterFieldDefinition.CurrentValues;

//Set the current values for the parameter field
crParameterDiscreteValue = new ParameterDiscreteValue();
crParameterDiscreteValue.Value = parameterValue;

//Add the first current value for the parameter field
crParameterValues.Add(crParameterDiscreteValue);

//All current parameter values must be applied for the parameter field.
crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
}

I'd really appreciate any assistance....

Cheers,

Brendan