Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
I want to execute a stored procedure from where the name of the stored procedure and the parameters are passed to the method in an array, the name of the stored procedure will always be at array[0] and the remaining parameters will follow... However the number of parameters can vary from 1 to many, any ideas guys (and girls) !
Posted
I want to execute a stored procedure from where the name of the stored procedure and the parameters are passed to the method in an array' date=' the name of the stored procedure will always be at array[0'] and the remaining parameters will follow... However the number of parameters can vary from 1 to many, any ideas guys (and girls) !

 

What database backend are you using, because it could make a difference in how you execute the code?

 

You will need to use a command object, either odbc or sql and then add a parameter and set it's value for each passed in parameter, as well as it's type and size. You will therefore also need to pass in the parameter name and parameter type (int, varchar, bit, etc), as well as the size expected (i.e. 50, 4, etc), along with the parameter value and sp name (you will want to use something other than a single array I think, otherwise you will have to do some kind of parsing on the backend, or use a multidimensional array). In this manner you could set it up based on the number of records in the array. If you are using an ODBC you will also need this number to generate the (?, ?, ?, ..., ?) string for the number of parameters. Also remember that if it is an ODBC you have to specifically set the return parameter on all sp execution, whereas with sql this is not necessary. When generating the parameters you will need to be wary of the type that the parameter is supposed to be, and set it accordingly (which also brings to mind the size variable). You will also need to take into account null values and how you will handle them, because what if an sp requires 10 values but you've only passed in 7 and the other three are supposed to 'just be null?'

 

Good Luck.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...