Building parameters for a stored proc

Author Message
spry

  • Total Posts : 1
  • Scores: 0
  • Reward points : 0
  • Joined: 10/7/2009
  • Status: offline
Building parameters for a stored proc Wednesday, October 07, 2009 4:32 PM (permalink)
0
I'm trying to dynamically build the parameters of a stored procedure. It can be one of several procedures with different arguments, so I don't know the names in advance. How would I add the parameters (I have an array of them) without knowing the parameter names? I tried the following:

    
 set cmd = Server.CreateObject("ADODB.Command")    
 cmd.ActiveConnection = cn    
 
 cmd.commandText = proc    
 cmd.commandType = 4    
                       
 dim param    
 For i = 0 To UBound(params)    
       set param = cmd.CreateParameter    
     param.Value = params(i)    
     cmd.Parameters.Append param    
 Next    
              
 set rs = cmd.Execute    
 


I get the following error at the line where I try to append:

ADODB.Parameters error '800a0e7c'
Parameter object is improperly defined. Inconsistent or incomplete information was provided.

Edit:

I tried:
  
 cmd.Parameters.Refresh  
 For i = 0 To UBound(params)  
     params(i) = Replace(params(i), "'", "")      
     cmd.Parameters(i).Value = CStr(params(i))  
 Next  
 


I get:
ADODB.Parameter error '800a0d5d'
Application uses a value of the wrong type for the current operation

Further edit: I don't know the parameter types either in advance but the arguments are assumed to be correct.
<message edited by spry on Wednesday, October 07, 2009 10:08 PM>
 
#1

    Online Bookmarks Sharing: Share/Bookmark

    Jump to:

    Current active users

    There are 0 members and 1 guests.

    Icon Legend and Permission

    • New Messages
    • No New Messages
    • Hot Topic w/ New Messages
    • Hot Topic w/o New Messages
    • Locked w/ New Messages
    • Locked w/o New Messages
    • Read Message
    • Post New Thread
    • Reply to message
    • Post New Poll
    • Submit Vote
    • Post reward post
    • Delete my own posts
    • Delete my own threads
    • Rate post

    2000-2012 ASPPlayground.NET Forum Version 3.9