
Crystal.Net parameter error...based on World Sales Report.rpt
Hi, I am using
Crystal Reports for Visual Studio .NET. I am trying to make
an example report work.
The directions said add a parameter. I went to the FieldExplorer, to
Parameter fields, and created a new one and gave it the name "Country". I
dragged it to the report and then used the "Select Expert" and set the
formula to: "{Customer.Last Year's Sales} > $0.00 and {Customer.Country} =
{?Country}" as the directions said.
I added the code (marked by *):
using CrystalDecisions.Shared; *
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
DataBind(); *
SetParameterFields(); *
Quote:
}
protected void SetParameterFields () *
{
ParameterFields paramFields =
CrystalReportViewer1.ParameterFieldInfo; *
ParameterField paramField = paramFields["Country"]; *
ParameterValues curValues = paramField.CurrentValues; *
ParameterDiscreteValue discreteValue = new ParameterDiscreteValue();
*
discreteValue.Value = TextBox1.Text; *
curValues.Add(discreteValue); *
CrystalReportViewer1.ParameterFieldInfo = paramFields; *
}
The code breaks/errors at: ParameterField paramField =
paramFields["Country"]: + paramFields["Country"] {"Specified argument was
out of the range of valid values." } System.ArgumentOutOfRangeException
The line before that populates: ParameterFields paramFields =
CrystalReportViewer1.ParameterFieldInfo puts zero (0) objects into
paramFields according to watch variables.
So why? The databind in init and then call to SetParameterFields doesn't
find my parameter placed on the report ?
Thanks, Jeff