I have a method which is supposed to run stored procedure on an oracle and sql server databases using dynamic parameters (you don't know the parameter names).
IDbCommand cmd = connection.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
int i = 0;
foreach (string parameterName in names)
{
var param2 = cmd.CreateParameter();
param2.ParameterName = parameterName + "__" + i.ToString();
param2.DbType = DbType.String;
param2.Direction = ParameterDirection.Input;
param2.Value = parameterName;
cmd.Parameters.Add(param2);
i++;
}
cmd.CommandText = "spName";
This code works on Oracle but sql server throws
Procedure or function 'pspName' expects parameter '@userID', which was not supplied
Because the parameter name in my code is not '@userID'. Thanks
DeriveParametersthat build the parameter collection for you. But you are still a long way from home. You need to create a specific SqlCommandBuilder or OracleCommandBuilder, then you need to create a viable way to setup the parameters values. If you really are ready to do all this work, then why don't you try to learn an ORM that will help you a lot in abstracting your database code from the underlying database system?