M
M
Is there any way to modify the following code so I can run it with any
number of paramNames as well as any number of paramValues? So far it
works with an array of paramValues, but since you can only pass a
variable number of parameters in the last parameter of a method, I'm
stumped.
Perhaps the paramValues could be multidimensional? And a (?) has to be
present for each paramName as well, correct?
Thanks in advance.
public DataSet returnStoredProc(string spName, string paramName, params
Object[] paramValues)
{
OdbcDataAdapter _da = new OdbcDataAdapter();
DataSet _ds = new DataSet();
OdbcConnection cn = new OdbcConnection(connectionString);
try
{
OdbcCommand _cmdSel = new OdbcCommand();
OdbcParameter prm = new OdbcParameter();
cn.Open();
_da.SelectCommand = _cmdSel;
_cmdSel.CommandText = "{CALL " + spName + " (?)}";
_cmdSel.CommandType = CommandType.StoredProcedure;
_cmdSel.Connection = cn;
for (int x = 0; x < paramValues.Length; x++)
_cmdSel.Parameters.Add("@" + paramName, paramValues[x]);
_da.Fill(_ds);
return _ds;
cn.Close();
}
}
number of paramNames as well as any number of paramValues? So far it
works with an array of paramValues, but since you can only pass a
variable number of parameters in the last parameter of a method, I'm
stumped.
Perhaps the paramValues could be multidimensional? And a (?) has to be
present for each paramName as well, correct?
Thanks in advance.
public DataSet returnStoredProc(string spName, string paramName, params
Object[] paramValues)
{
OdbcDataAdapter _da = new OdbcDataAdapter();
DataSet _ds = new DataSet();
OdbcConnection cn = new OdbcConnection(connectionString);
try
{
OdbcCommand _cmdSel = new OdbcCommand();
OdbcParameter prm = new OdbcParameter();
cn.Open();
_da.SelectCommand = _cmdSel;
_cmdSel.CommandText = "{CALL " + spName + " (?)}";
_cmdSel.CommandType = CommandType.StoredProcedure;
_cmdSel.Connection = cn;
for (int x = 0; x < paramValues.Length; x++)
_cmdSel.Parameters.Add("@" + paramName, paramValues[x]);
_da.Fill(_ds);
return _ds;
cn.Close();
}
}