You need to create a new Field parameter and a value for both parameters. Your current code adds the parameter, changes it (changes the name and value), and adds the same object again. This should be correct:
{ ReportDocument reportDocument = new ReportDocument(); ParameterFields paramFields = new ParameterFields(); // ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue(); ParameterField paramField = new ParameterField(); ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue(); paramField.Name = "@Dept"; paramDiscreteValue.Value = TextBox1.Text.ToString(); paramField.CurrentValues.Add(paramDiscreteValue); paramFields.Add(paramField); paramField = new ParameterField(); // <-- This line is added paramDiscreteValue = new ParameterDiscreteValue(); // <-- This line is added paramField.Name = "@Name"; paramDiscreteValue.Value = TextBox2.Text.ToString(); paramField.CurrentValues.Add(paramDiscreteValue); paramFields.Add(paramField); CrystalReportViewer1.ParameterFieldInfo = paramFields; reportDocument.Load(Server.MapPath("CrystalReport.rpt")); CrystalReportViewer1.ReportSource = reportDocument; reportDocument.SetDatabaseLogon("sa", "sa", "OPWFMS-7KYGZ7SB", "test");
}
EDIT: The error mentioned in the comment is probably because there are two definitions of the variable paramField or paramDiscreteValue in the code. In one C # method, you cannot define a variable with the same name more than once. Try the code above as it is written, and if you still get a compiler error, insert the full error text here.
zendar
source share