protected override void DoAssignParameterValues()
{
if (SameNumberOfParametersAndValues() == false)
{
throw new InvalidOperationException(SR.ExceptionMessageParameterMatchFailure);
}
int inputParameterCount = 0;
for (int i = 0; i < this.command.Parameters.Count; i++)
{
IDataParameter parameter = this.command.Parameters[i];
// There used to be code here that checked to see if the parameter was input or input/output
// before assigning the value to it. We took it out because of an operational bug with
// deriving parameters for a stored procedure. It turns out that output parameters are set
// to input/output after discovery, so any direction checking was unneeded. Should it ever
// be needed, it should go here, and check that a parameter is input or input/output before
// assigning a value to it.
if (parameter.Direction == ParameterDirection.InputOutput | parameter.Direction == ParameterDirection.ReturnValue)
{
SetParameterValue(parameter.ParameterName, null);
}
else
{
SetParameterValue(parameter.ParameterName, this.parameterValues[inputParameterCount]);
inputParameterCount++;
}
}
}
private bool SameNumberOfParametersAndValues()
{
int numberOfOutputParameters = 0;
for (int i = 0; i < this.command.Parameters.Count; i++)
{
IDataParameter parameter = this.command.Parameters[i];
if (parameter.Direction == ParameterDirection.InputOutput | parameter.Direction == ParameterDirection.ReturnValue)
{
numberOfOutputParameters++;
}
}
return this.command.Parameters.Count - numberOfOutputParameters == this.parameterValues.Length;
}