Ok, you're setting the parameter in the Report file, but not in the report in the viewer. Once you set the ReportSource in the viewer, the report there is a different object than the report document - changing one will NOT change the other. I'm assuming that rptDoc is a ReportDocument object.
A couple of rules for setting parameters in reports from code so that the viewer doesn't show the parameter screen:
1. Don't set values for subreport links (parameter name starts with "Pm").
2. You must set some sort of value for ALL other parameters - even if there is a default value declared for the parameter.
In our web application, here's the code we use to set parameters:
ParameterDiscreteValue discreteVal = new ParameterDiscreteValue();
ParameterValues curvalues = new ParameterValues();
foreach (ParameterFieldDefinition parafld in crReport.DataDefinition.ParameterFields)
{
//Get the value of the param from the QueryString for the viewer page
discreteVal.Value = Request.QueryString[parafld.ParameterFieldName];
//There is no param with this name in the QueryString so set default val
if (discreteVal.Value == null)
{
if(parafld.ParameterFieldName.Substring(0,2) != "Pm")
{
switch (parafld.ValueType.ToString())
{
case "NumberField":
discreteVal.Value = 1;
break;
case "StringField":
discreteVal.Value = "A";
break;
case "DateField":
discreteVal.Value = "01/01/1990";
break;
case "CurrencyField":
discreteVal.Value = "0";
break;
case "Int32sField":
discreteVal.Value = "0";
break;
}
curvalues.Add(discreteVal);
parafld.ApplyCurrentValues(curvalues);
}
//there is a value for this param, so set it.
else if (discreteVal.Value != null)
{
curvalues.Add(discreteVal);
parafld.ApplyCurrentValues(curvalues);
}
}
We then set the ConnectionInfo for the tables and only after all of that is complete do we set the ReportSource for the viewer.
-Dell
Edited by hilfy - 29 Sep 2009 at 8:25am