2

我正在尝试在 ASP-Classic 中转换未参数化的 SQL Server 2008 R2 Express 查询,因此我执行了以下操作(请参见下面的代码),但我一直收到错误消息:

对象不支持此属性或方法:“参数”

有人可以告诉我我做错了什么!

谢谢!

<%
' OPEN DATABASE
dim objConn, objRS, objTRS, objUnit
dim strConnection
set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "Driver={SQL Server};Server=MSSQLSrv;Database=DbTest;UID=blablabala;PWD=blablabala"
objConn.Open strConnection
set objRS = Server.CreateObject("ADODB.Recordset")
set objRS.ActiveConnection = objConn
strQuery = "SELECT USERNAME,PASSWORD from CUSTOMERS where EMAIL=?"
objRS.Parameters(0) = Request.QueryString("email")
objRS.Open strQuery
%>
4

3 回答 3

2

如果您尝试使其成为参数查询,则需要先创建命令对象和参数。例如:

' create your command object
Const adCmdText = &H0001
Set objCmd = Server.CreateObject("ADODB.Command")
objCmd.ActiveConnection = YourConnectionString
objCmd.CommandType = adCmdText    ' Evaluate as textual definition, not stored procedure

'now create query and add parameters
strQuery = "SELECT USERNAME,PASSWORD from CUSTOMERS where EMAIL=?"  
objCmd.CommandText=strQuery
objCmd.Parameters.Append = objCmd.CreateParameter("ParameterName", ParameterType, adParamInput,   parameterSize, ParameterValue)
SET objRS = objCmd.execute(strSQL)
Set objCmd=Nothing
于 2012-08-20T20:45:52.247 回答
2

参数集合在command对象而不是recordset.

这是一些有效的 VB6 代码,参数名称并不重要,因为参数顺序很重要。

    Dim rst As Recordset
    Dim cmd As ADODB.Command
    Set cmd = New Command

    With cmd
        .CommandText = "SELECT USERNAME,PASSWORD from CUSTOMERS where EMAIL=?" ' this proc also returns factor info
        .CommandType = adCmdText
        Set .ActiveConnection = objconn
        .Parameters.Append .CreateParameter("@Email", adVarChar, adParamInput, 50, "Email")

        Set rst = cmd.Execute
    End With
于 2012-08-20T20:55:24.933 回答
1

你可以这样做:

    ' OPEN DATABASE
    dim objConn,objRS,objTRS,objUnit

   Const adCmdText = &H0001

    Set objConn = Server.CreateObject("ADODB.Command") 
    objConn.ActiveConnection = "Driver={SQL Server};Server=MSSQLSrv;Database=DbTest;UID=blablabala;PWD=blablabala"

   objConn.CommandType = adCmdText

    strQuery = "SELECT USERNAME,PASSWORD from CUSTOMERS where EMAIL=?"
    objConn.CommandText=strQuery 
    objConn.Parameters(0) = Request.QueryString("email")
    SET objRS = objConn.execute(strQuery)
于 2012-08-20T22:11:24.540 回答