您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

MySQL /经典ASP-参数化查询

MySQL /经典ASP-参数化查询

第二个代码段中的代码是正确的,但应将其应用于新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(在我的示例中已更正)。

MySQL 2022/1/1 18:45:38 有422人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶