I'm accessing a stored procedure and I'm trying to pass some parameters to it. I have the following loop that adds all parameters:
List<string> paramNames = new List<string> {
"@EmployeeId",
"@Location",
"@StartYear",
"@EndYear",
"@Department",
"@Title",
"@FileName"
};
List<string> paramValues = new List<string> {
EmployeeId,
Location,
StartYear,
EndYear,
Department,
Title,
FileName
};
// Add the input parameter and set its properties.
SqlParameter parameter;
for (int i = 0; i < paramNames.Count(); i++)
{
parameter = new SqlParameter();
parameter.ParameterName = paramNames[i];
parameter.Value = paramValues[i];
command.Parameters.Add(parameter);
}
the first parameter is "EmployeeId" and this value is coming from the method arguments. This parameter can either be a string value "All" or it can be an int value with the employee id.
-How do I pass its value to the stored procedure so it accepts a string or an int.
-And how do I tell it that if its "All" then I want all employees, otherwise if its a number, I want the employee with that number ID?
Dictionary<string,string>for your parameters and their values, or betterList<SqlParameter>where you can also specify the type of parameters.