对象不支持此 属性 或方法:'Parameters.Append'

Object doesn't support this property or method: 'Parameters.Append'

我目前正在研究经典 ASP 和 MySQL 数据库的参数化查询。我有一个旧页面,访问者可以在其中使用从数据库(例如,国家、州、县)填充的各种分层下拉列表来搜索数据库。因此,每个下拉菜单的内容将根据其他下拉菜单(总共 7 个)所做的选择进行过滤。我正在尝试转换此页面,以便它使用参数化查询。

在网上搜索时,我认为我有正确创建查询的必要步骤,但我收到以下错误。

Microsoft VBScript 运行时错误“800a01b6” 对象不支持此 属性 或方法:'Parameters.Append'

我的县下拉列表代码如下。

    Dim strConnString
    strConnString = "Driver={MySQL ODBC 5.2w Driver}; Server=**servername**; Option=16834; User Id=**username**; Password=**pw**; Database=**db**;"
    
    Dim objConn7, objRS7, cmd7
    Set objConn7 = Server.CreateObject("ADODB.Connection")
    objConn7.Open strConnString
    
    Set cmd7 = Server.CreateObject("ADODB.Command")
    cmd7.ActiveConnection = objConn7
    cmd7.Prepared = true
    cmd7.CommandType = adCmdText
    
    If strSt <> "" Then
        If strOrd <> "" Then
            If strFam <> "" Then
                If strGen <> "" Then
                    If strSp <> "" Then
                        cmd7.CommandText = "SELECT DISTINCT(County) FROM specimens WHERE taxOrder= ? AND taxFamily= ? AND Genus= ? AND Species= ? AND Country= ? AND State= ? ORDER BY County ASC;"
                        Set cmd7.parameters.Append = cmd7.CreateParameter("@taxOrder", adVarChar, adParamInput, 35, strOrd)
                        Set cmd7.parameters.Append = cmd7.CreateParameter("@taxFamily", adVarChar, adParamInput, 35, strFam)
                        Set cmd7.parameters.Append = cmd7.CreateParameter("@Genus", adVarChar, adParamInput, 25, strGen)
                        Set cmd7.parameters.Append = cmd7.CreateParameter("@Species", adVarChar, adParamInput, 60, strSp)
                        Set cmd7.parameters.Append = cmd7.CreateParameter("@Country", adVarChar, adParamInput, 30, strCn)
                        Set cmd7.parameters.Append = cmd7.CreateParameter("@State", adVarChar, adParamInput, 30, strSt)
                    Else
                        cmd7.CommandText = "SELECT DISTINCT(County) FROM specimens WHERE TaxOrder= ? AND TaxFamily= ? AND Genus= ? AND Country= ? AND State= ? ORDER BY County ASC;"
                        Set cmd7.parameters.Append = cmd7.CreateParameter("@taxOrder", adVarChar, adParamInput, 35, strOrd)
                        Set cmd7.parameters.Append = cmd7.CreateParameter("@taxFamily", adVarChar, adParamInput, 35, strFam)
                        Set cmd7.parameters.Append = cmd7.CreateParameter("@Genus", adVarChar, adParamInput, 25, strGen)
                        Set cmd7.parameters.Append = cmd7.CreateParameter("@Country", adVarChar, adParamInput, 30, strCn)
                        Set cmd7.parameters.Append = cmd7.CreateParameter("@State", adVarChar, adParamInput, 30, strSt)
                    End If
                Else
                    cmd7.CommandText = "SELECT DISTINCT(County) FROM specimens WHERE TaxOrder= ? AND TaxFamily= ? AND Country= ? AND State= ? ORDER BY County ASC;"
                    Set cmd7.parameters.Append = cmd7.CreateParameter("@taxOrder", adVarChar, adParamInput, 35, strOrd)
                    Set cmd7.parameters.Append = cmd7.CreateParameter("@taxFamily", adVarChar, adParamInput, 35, strFam)
                    Set cmd7.parameters.Append = cmd7.CreateParameter("@Country", adVarChar, adParamInput, 30, strCn)
                    Set cmd7.parameters.Append = cmd7.CreateParameter("@State", adVarChar, adParamInput, 30, strSt)
                End If
            Else
                cmd7.CommandText = "SELECT DISTINCT(County) FROM specimens WHERE TaxOrder= ? AND Country= ? AND State= ? ORDER BY County ASC;"
                Set cmd7.parameters.Append = cmd7.CreateParameter("@taxOrder", adVarChar, adParamInput, 35, strOrd)
                Set cmd7.parameters.Append = cmd7.CreateParameter("@Country", adVarChar, adParamInput, 30, strCn)
                Set cmd7.parameters.Append = cmd7.CreateParameter("@State", adVarChar, adParamInput, 30, strSt)
            End If
        Else
            cmd7.CommandText = "SELECT DISTINCT(County) FROM specimens WHERE Country= ? AND State= ? ORDER BY County ASC;"
            Set cmd7.Parameters.Append = cmd7.CreateParameter("@Country", adVarChar, adParamInput, 30, strCn)   <======  Error thrown here!
            Set cmd7.Parameters.Append = cmd7.CreateParameter("@State", adVarChar, adParamInput, 30, strSt)
        End If
    
        Set objRS7 = cmd7.Execute
    %>
    <!-- START County dropdown -->
    <div id="f-county" class="form-inline"><label for="county"><strong>County: </strong></label>
        <select id="county" name="county" tabindex="7" onchange="window.location=document.NewRecord.county.options[document.NewRecord.county.selectedIndex].value">
        <option value="dbSearch.asp?uid=<%=strUName%>&q=&o=<%=strOrd%>&f=<%=strFam%>&g=<%=strGen%>&sp=<%=strSp%>&cn=<%=strCn%>&st=<%=strSt%>&co=&recs=<%=strRecs%>&page=<%=strPage%>" <%If strCo = "" Then Response.Write " selected" End If%>>Select</option>
        <% If NOT objRS7.EOF Then
            WHILE NOT objRS7.EOF
                If objRS7("County") <> "" Then %>
                    <option value="dbSearch.asp?uid=<%=strUName%>&q=&o=<%=strOrd%>&f=<%=strFam%>&g=<%=strGen%>&sp=<%=strSp%>&cn=<%=strCn%>&st=<%=strSt%>&co=<%=objRS7("County")%>&recs=<%=strRecs%>&page=<%=strPage%>" <%If strCo = objRS7("County") Then Response.Write " selected" End If%>><%=objRS7("County")%></option>
        <%      End If
                objRS7.MoveNext
                WEND
            End If
            objRS7.Close
            Set objRS7 = Nothing
            objConn7.Close
            Set objConn7 = Nothing
            Set cmd7 = Nothing
        %>
        </select>
    </div> <!-- END County dropdown -->
    <% End If %>

因此,当国家和州下拉菜单被选中并且县下拉菜单应该出现时,我得到了上面列出的错误。导致错误的行如上所示 (<====)。注意,我还没有将参数化查询命令添加到其他下拉列表中,所以这就是为什么它们可以工作而县级的不能。

我的问题是,任何人都可以在代码中看到可能导致此错误的原因。根据错误文本,似乎 cmd7 对象可能无法正确创建或识别(?),但我遵循了我在 Stack Overflow 等网站上看到的陈述。任何帮助将不胜感激。

此外,我是否正确地过滤了下拉菜单,或者是否有更好的方法使用参数来完成此操作?

正如上面@Flakes 和@user692942 指出的那样,append 方法不接受赋值 (=),因此修复原始错误的正确解决方案应该是按如下方式编写 append 语句:

cmd7.Parameters.Append cmd7.CreateParameter("@Country", adVarChar, adParamInput, 30, strCn)