在.asp中使用cmd执行并将varchar用于存储过程

时间:2015-09-23 15:30:48

标签: sql asp-classic ado

我试图在asp页面中使用cmd将值传递给存储过程,但我一直这样:

  

类型不匹配:'cint'

     

/default/current/purchasing.asp,第512行

“类别”列是varchar。我想我必须传递数据类型 如果我使用的是int列,我只需使用int(sField_PO)

如何传递varchar数据类型?

set prmCategory = server.CreateObject("ADODB.Parameter")
    prmCategory.Name = "@Category"
    prmCategory.Direction = 1
    prmCategory.Type = 3    'adVarChar  
    prmCategory.Value = (sField_CATEGORY)
    cmd.Parameters.append prmCategory   

1 个答案:

答案 0 :(得分:0)

已经尝试过了吗?

set objCmd = Server.CreateObject("ADODB.Command")
with objCmd
    .ActiveConnection   = MyConnection
    .CommandType        = 4 'adCmdStoredProc
    .CommandText        = "MY STORED PROCEDURE NAME"
    .Parameters.Append .CreateParameter("@Category", 200, 1, 255, sField_CATEGORY)
    .Execute
end with
set objCmd = nothing

如果包含类型库,则可以使用常量而不是数字

<!--METADATA TYPE="typelib" UUID="00000205-0000-0010-8000-00AA006D2EA4" NAME="ADODB Type Library" --> 
set objCmd = Server.CreateObject("ADODB.Command")
with objCmd
    .ActiveConnection   = MyConnection
    .CommandType        = adCmdStoredProc
    .CommandText        = "MY STORED PROCEDURE NAME"
    .Parameters.Append .CreateParameter("@Category", adVarChar, adParamInput, 255, sField_CATEGORY)
    .Execute
end with
set objCmd = nothing