0
Answer

Using Crystalreportviewer with parameters

Stevie Krynauw

Stevie Krynauw

15y
4.4k
1

Hi there.

I have the following code

private void button1_Click(object sender, EventArgs e)
{
   SetParameterFieldInfo(
"JobRequestNo", 200);
   crystalReportViewer1.RefreshReport();
}

private void SetParameterFieldInfo(String fieldName, int fieldValue)
{
  
ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();
   parameterDiscreteValue.Value = fieldValue;
   ParameterValues currentParameterValues = new ParameterValues();
   currentParameterValues.Add(parameterDiscreteValue);
   ParameterField parameterField = new ParameterField();
   parameterField.Name = fieldName;
   parameterField.CurrentValues = currentParameterValues;
  
ParameterFields parameterFields = new ParameterFields();
   parameterFields.Add(parameterField);
   crystalReportViewer1.ParameterFieldInfo = parameterFields;
}

OK, my problem is that when I execute the line to call SetParameterFieldInfo only, then nothing happens. When I call the RefreshReport() method, it prompts me for the parameter value, which I don't want. When I type in the parameter value, the report displays correctly, so the connections and stuff seems ok.

How can I have my update my report with the new parameters passed from code without having a popup asking for the parameter values?

Thanks