Setting ReportParameter that's not a string

633 Views Asked by At

In C# I'm trying to set the report parameters for an SSRS rdlc file. First of all, am I doing this correctly?

  1. GetParameters() to return a collection of the parameter info
  2. Create a list of new ReportParameter objects, assigning name and values
  3. Call SetParameters with the new ReportParameter list as the argument.

Assuming I'm handling this correctly, here's my conundrum. Code is vastly simplified for this example:

var reportParams = new List<ReportParameter>();
foreach (var param in report.GetParameters()) {
    reportParams.Add(new ReportParameter(param.Name, "1"));
}
report.SetParameters(reportParams);

When the report parameter type is an integer, I get the following error on the SetParameters call:

The value provided for the report parameter 'intActualWeight' is not valid for its type.

But when I try to set the parameter value as an integer:

reportParams.Add(new ReportParameter(param.Name, 1));

The IDE says it cannot convert from int to string. Looking at the overloads for new ReportParameter, it is expecting a string or string array.

What am I doing wrong? Thanks in advance!

Steve.

1

There are 1 best solutions below

0
minTwin On

Heres what worked for me:

int paramName = 1;
string paramNameAsString = paramName.ToString();
ReportParameter[] reportParameter = new ReportParameter[1];
reportParameter[0] = new ReportParameter("ParamName", paramNameAsString);
ReportViewer1.ServerReport.SetParameters(reportParameter);
ReportViewer1.ServerReport.Refresh();