I use C# and I instantiate a DbCommand
in order to execute an Oracle stored procedure.
My question is: why does the procedure receive the value through a different named parameter than the on in db?
When I add a parameter to the dbCommand
:
...
string value = "Whatever"
db.AddInParameter(dbCommand,"WrongParamName",DbType.String);
db.SetParameterValue(dbCommand, "WrongParamName", value);
and I execute:
dataSet = db.ExecuteDataSet(dbCommand);
It will pass the dbCommand
parameter to the stored procedure parameter correctly.
Why is that?
Does it set the value to the first parameter without a value or is it based on position?
If it's based on position why do we need the name for?
Is the name only to help the dev understand the code?
I need to know if you execute the stored procedure like "EXEC sp_StoredProcedure @Param1 = @Param1, @Param2 = @Param2" or "EXEC sp_StoredProcedure @Param1, @Param2". In the first case, if you change the order of parameters in the sp, the call won't be affected. In the second case on the other hand, it does, because first parameter from the command fulfill the first parameter from the sp, the second to second and so on. If you cannot obtain a list of parameter names you can at least ask the other developer to not change the order and add parameters only to the end of the parameter list in stored procedure. If you cannot do this either, you have nothing else to do then to pray not to change them. With some scripts, you can determine the list of parameters though (see this How to get stored procedure parameters details?). You can execute this command like an ordinary select statement.