使用Classic ASP将变量传递给存储过程

mac*_*lot 1 sql stored-procedures asp-classic

好的,所以我试图将一些字符串变量从经典的ASP页面传递到MSSQL2000 db:

strSQL = "exec UpdateEvent " & xID & ",'" & xEventID & "'," & xEventDisplayName & "," & xEventType & "," & xEventStatus & "," & xStartDate & "," & xEndDate & "," & xSurveyTemplateID & ""
Run Code Online (Sandbox Code Playgroud)

然而我最终得到了错误(包括写出strSQL内容):

exec UpdateEvent 1,'1-44KTDL',,,,,,

Microsoft OLE DB Provider for SQL Server错误'80040e14'

第1行:','附近的语法不正确.

/eventedit.asp,第225行

现在我不确定是否是EventID变量中的破折号导致我的问题(或者当有数据时,为什么所有其他变量都会出现空值...).我已经尝试了许多引号和抽搐的组合来安抚语法解释器,但无济于事.我究竟做错了什么?有没有更好的方法来执行这个简单的存储过程调用?

Rub*_*ias 5

那非常糟糕; 您的代码受SQL注入攻击,需要尽快修复.

<!--#include virtual="/ASPSAMP/SAMPLES/ADOVBS.INC"-->
<%
Set cmd = Server.CreateObject("ADODB.Command")
' ... open connection and stuff ... '
cmd.CommandText = "UpdateEvent"
cmd.CommandType = adCmdStoredProc
cmd.Parameters.Refresh

cmd.Parameters(1) = xID 
cmd.Parameters(2) = xEventID 
cmd.Parameters(3) = xEventDisplayName 
cmd.Parameters(4) = xEventType 
cmd.Parameters(5) = xEventStatus 
cmd.Parameters(6) = xStartDate 
cmd.Parameters(7) = xEndDate 
cmd.Parameters(8) = xSurveyTemplateID
cmd.Execute
%>
Run Code Online (Sandbox Code Playgroud)