Hi,
I tried to create a utility method to accept the name of a stored procedure and an array of OdbcParameter objects. When I try to add the parameters from the array in the code, the parameters aren't recognized:
foreach (OdbcParameter prmin prm_array)cmd.Parameters.add (prm);
OR
cmd.Parameters.AddRange (prm_array);
However, when I hardcode the parameters without using the argument of the function, it works perfectly:
cmd.Parameters.Add ("@.login", OdbcType.VarChar, 50,"Joe");cmd.Parameters.Add ("@.password", OdbcType.VarChar, 50,"Bob");
I know the method calling the utility function is passing the parameters correctly; in fact, if I hard code the parameters in the utility function but add them with a foreach like above or using the AddRange function, it just does not recognize the parameters.
I've worked too long on this so I'm using an inelegant solution, but this nuance is very frustrating. Any possible insight?
~ mellamokbIs the cmd object an ODBCCommand object. If not, this sure won't work.|||
Yep. I only use Odbc.... objects.
~ mellamokb
|||can you post the entire function, this would be helpful
thanks
|||Yes, if it was not recognized, what runtime exception or compile time error was thrown?|||I got it to work by reconstructing the parameters from an OdbcParameter array passed and by using the AddWithValue command:
foreach (OdbcParameter prmin prm_array) cmd.Parameters.AddWithValue(prm.ParameterName, prm.Value);
I'll call that good enough; but it doesn't make sense why cmd.Parameters.Add(prm_object) is different than cmd.Parameters.Add([parameter_name], [datatype], [datasize], [value]) when the prm_object and the hard-coded parameters are the same information.
This situation is independent of the function it is in; I've generalized to any situation, and there's no reason why it would work in a modified test case but not in the utility function I've created.
But I've seen stranger things, I guess.
Kevin Yu: The runtime exception is simply that the command cannot find the needed parameter, as if I hadn't passed it at all, when I use Add(prm_object); but using the four parameter version of Add works fine, even if the four parameters are the same as the four used to construct the new OdbcParameter object.
~ mellamokb
No comments:
Post a Comment