>>>Hi,
>>>
>>>I am working on a case of replacing what the gurus call "programming to class" with "programming to interface" for the following code:
>>>
>>>First, the code the way it works currently (not with interface)
>>>
>>>OleDbCommand oCommand = new OleDbCommand();
>>>// connectionString is valid string (not shown here)
>>>OleDbConnection oConnection = new OleDbConnection(connectionString);
>>>oConnection.Open();
>>>oCommand.CommandText = "SP_MyProc";
>>>oCommand.CommandType = CommandType.StoredProcedure;
>>>oCommand.Parameters.AddWithValue( "@par1", cPar1 );
>>>
>>>
>>>The following is my replacement code (simplified):
>>>
>>>IDbCommand oCommand;
>>>idbCommand = new OleDbCommand();
>>>// connectionString is valid string (not shown here)
>>>OleDbConnection oConnection = new OleDbConnection(connectionString);
>>>oConnection.Open();
>>>oCommand.CommandText = "SP_MyProc";
>>>oCommand.CommandType = CommandType.StoredProcedure;
>>>oCommand.Parameters.AddWithValue( "@par1", cPar1 );
>>>
>>>
>>>The problem is that in the lower case code the method .AddWithValue has an error:
>>>
>>>'System.Data.IDataParameterCollection' does not contain definition for 'AddWithValue'
>>>
>>>
>>>What am I missing? TIA.
>>
>>I tried to replace method AddWithValue with Add() but Add() only takes one parameter. So I am not sure how to pass the parameter name and the value if I can't use AddWithValue(). Any suggesetions?
>
>What do you mean by Add taking one parameter? Which overload did you check? Of course, you can create a parameter object first and pass it to Add method, but Add has a lot of overloads with many parameters.
In the case of IDbCommand.Parameters there is no other overload - it's an implementation of IList. ie. Add(object)....