classic asp stored procedures parameters

2019-05-07 01:48发布

问题:

I've been looking around how to call a stored procedure from classic asp and pass a parameter into it below is my stored procedure which works fine

CREATE PROCEDURE Paging_Movies
@alphaChar char(1)
AS
if @alphaChar = '#'
select * from Movies where movies like '[^a-z]%'
else
select * from Movies where movies like @alphaChar + '%'

and my vbscript code so far -

Set objCon = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")
set objComm = CreateObject("ADODB.Command")

objCon.Open "Provider=SQLOLEDB.1;Password=xxxx;Persist Security Info=True;User ID=xxxx;Initial Catalog=Movies;Data Source=xxxx-PC"

objComm.ActiveConnection = objCon
objComm.CommandType = 4
objComm.CommandText = "Paging_Movies"

objRS.open objComm.CommandText, objCon

回答1:

You're looking for the Parameters property.

objComm.Parameters.Append objComm.CreateParameter("alphaChar", adChar, adParamInput)
objComm.Parameters("alphaChar") = "a"
objComm.Execute

Oh Lawdy I'm writing VBScript again.



回答2:

You can pass the paramter like as below

LInk for it : http://www.devguru.com/technologies/ado/quickref/command_createparameter.html

Set objParameter = objCommand.CreateParameter
objParameter.Name = "alphaChar"
objParameter.Type = adChar
objParameter.Direction = adParamInput
objParameter.Value = "a"
or
Set objParameter = objCommand.CreateParameter ("alphaChar", adChar, adParamInput, "a")