I'm trying to get the parameter of user name and replace its value with the session's username so I can pass to a Stored procedure inside the DRL to generate a table timestamp with this user name. The parameter "username" is one of the parameters of the RDL which comes with default value and I'm trying to change it with the following code.
Replacing one of the ReportParameters:
var userParameter = GetUserParameter();
if (userParameter != null)
{
newParameters.Remove(newParameters.FirstOrDefault(param => param.Name.Contains(CurrentUserParameterName)));
newParameters.Add(userParameter);
}
Finding username ReportParameters:
var paremeters = ReportViewer.ServerReport.GetEditableHiddenParameters();
//finds parameter by its name, pelase view const value in CurrentUserParameterName
var userParameter = paremeters.FirstOrDefault(param => param.Name.Contains(CurrentUserParameterName));
if (userParameter != null)
{
userParameter.Values.Clear();
userParameter.Values.Add(Utils.GetUserName());
}
return userParameter;
Set Parameters to ServerReport:
ReportViewer.ServerReport.SetParameters(parameters);
After running the report, I get the message "The 'username' parameter is missing a value"
When I debug and look in the ServerReport.GetParameters()
I can see that I do have the ReportParameter "username", I do have values (the new values), but its State is "MissingValidValue".
What am I doing wrong? Thanks in advance, Eddie