Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Passing multiple values to a parameterised query


Message #1 by "Nick Jones" <nick.jones@g...> on Fri, 19 Oct 2001 17:40:41
I have an sql query ...



"SELECT conid,partno,qty from sco where conid in ?" 



and am trying to pass a list of values into the query to return a 

recordset using the following code.



set prmPal=server.CreateObject("ADODB.Parameter")



' I don't know what prmPal.Type to use



prmPal.Direction=adparaminput

prmPal.Value= pallist ' this is my list of values

command.Parameters.Append prmPal



etc



Is this the method to use or am I going about it the wrong way? Any 

suggestions would be greatly appreciated.



Message #2 by "J House" <jesse@s...> on Tue, 23 Oct 2001 16:24:16
I think you would want to use adVarChar.

is this query a Stored procedure?



There are many ways to call it, this is how i usually do it.



if you are calling storedproc

sSql = "your_sp_name"

With oCmd

  .ActiveConnection = oConn

  .CommandText = sSql

  .CommandType = adCmdStoredProc

  .Parameters.Append oCmd.CreateParameter ("PallList", adVarChar, 

adParamInput, 50)

  .Parameters("PallList").Value = pallist

End With

set oRS = oCmd.Execute 



' note .Parameters.Append oCmd.CreateParameter ("PallList", adVarChar, 

adParamInput, 50) ' the number 50 is the length of the varchar and should 

match the length in your storedproc.





If you are not using a storedproc, you could use

sSql = "SELECT conid,partno,qty from sco where conid in '" & pallist & "'"

With oCmd

  .ActiveConnection = oConn

  .CommandText = sSql

  .CommandType = adCmdStoredProc

End With

set oRS = oCmd.Execute 



' no parameters, I don't know off hand the proper way to use the parameter 

object when you are not calling a stored proc.



note: you may want to put this at the top of your page

<!-- METADATA TYPE="typelib" FILE="C:\Program Files\Common 

Files\System\ado\msado15.dll" -->

This loads all the ado constants into your page as you need them, so you 

won't have to declare them yourself.





Hope this helps.



  







> I have an sql query ...

> 

> "SELECT conid,partno,qty from sco where conid in ?" 

> 

> and am trying to pass a list of values into the query to return a 

> recordset using the following code.

> 

> set prmPal=server.CreateObject("ADODB.Parameter")

> 

> ' I don't know what prmPal.Type to use

> 

> prmPal.Direction=adparaminput

> prmPal.Value= pallist ' this is my list of values

> command.Parameters.Append prmPal

> 

> etc

> 

> Is this the method to use or am I going about it the wrong way? Any 

> suggestions would be greatly appreciated.

> 


  Return to Index