第二个代码段中的代码是正确的,但应将其应用于新ADODB.Command
对象,而不是Connection
对象:
username = Trim(Request("username"))
'-----Added this-----
Dim cmdContent
Set cmdContent = Server.CreateObject("ADODB.Command")
' Use this line to associate the Command with your prevIoUsly opened connection
Set cmdContent.ActiveConnection = connContent
'--------------------
cmdContent.Prepared = True
Const ad_nVarChar = 202
Const ad_ParamInput = 1
sql = " SELECT * FROM users WHERE (username=?) ; "
Set newParameter = cmdContent.CreateParameter("@username", ad_nVarChar, ad_ParamInput, 20, username)
cmdContent.Parameters.Append newParameter
cmdContent.CommandText = sql
Set rs = cmdContent.Execute
If NOT rs.EOF Then
' Do something...
End If
rs.Close
顺便说一句,有一个拼写为adParamInput
而不是的错字ad_ParamInput
(在我的示例中已更正)。