Sql 将参数传递到存储过程经典asp

Sql 将参数传递到存储过程经典asp,sql,stored-procedures,vbscript,asp-classic,Sql,Stored Procedures,Vbscript,Asp Classic,我以前也问过类似的问题,虽然我试图修复我以前的代码,但现在却出现了一个错误:“参数类型错误,超出了可接受的范围,或者相互冲突。”。我想传递一个字符作为参数来查询数据库,然后使用记录集打印到网页。下面是我的经典asp代码 Set objCon = CreateObject("ADODB.Connection") Set objRS = CreateObject("ADODB.Recordset") set objComm = CreateObject("ADODB.Command") objCo

我以前也问过类似的问题,虽然我试图修复我以前的代码,但现在却出现了一个错误:“参数类型错误,超出了可接受的范围,或者相互冲突。”。我想传递一个字符作为参数来查询数据库,然后使用记录集打印到网页。下面是我的经典asp代码

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

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

objComm.ActiveConnection = objCon.ConnectionString
objComm.CommandText = "Paging_Movies"
objComm.CommandType = adCmdStoredProc

Set objParameter = objComm.CreateParameter
objParameter.Name = "alphaChar"
objParameter.Type = adChar
objParameter.Direction = adParamInput
objParameter.Value = "a"

objComm.Parameters.Append objParameter

set objRs = objComm.Execute
此外,我的存储过程如下所示-

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 + '%'

可能要添加两次参数。尝试替换:

objComm.ActiveConnection = objCon.ConnectionString
objComm.CommandText = "Paging_Movies"
objComm.CommandType = adCmdStoredProc

Set objParameter = objComm.CreateParameter
objParameter.Name = "alphaChar"
objParameter.Type = adChar
objParameter.Direction = adParamInput
objParameter.Value = "a"

Set objParameter = objCommand.CreateParameter ("alphaChar", adChar, _
    adParamInput, "a")

objComm.Parameters.Append objParameter
只要:

objCommand.CreateParameter ("alphaChar", 129, 1, 1, "a")

根据您的评论进行编辑,建议使用中的
adChar
(129)和
adParamInput
(1)的数值。

不幸的是,我最终导致类型不匹配?@kurupt89:是否尝试指定长度为1?谢谢你的回答帮助我找到了答案。我还必须将adChar和adParamInput更改为数字表示