我正在创建一个界面页面,它将为person_id提取response.querystring,然后在查询中将其用作parm来查找信息。以下是行不通的,但是当我硬编码它的ID时。语法上还有一些东西。
dim id
dim conn
dim cmdQuery
Const adCmdText = 1
Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adVarChar=200
Const adInteger = 3
set conn = server.CreateObject ("ADODB.Connection")
conn.Open "DRIVER={SQL Server};" & _
"SERVER=xxx.xx.x.xxx,xxxx;" & _
"UID=sa;" & _
"PWD=sa;" & _
"DATABASE=person"
id = 1019438
set cmdQuery = CreateObject("ADODB.Command")
set prm = cmdQuery.CreateParameter("ID", adInteger, 1, , )
With cmdQuery
Set .ActiveConnection = conn
.CommandType = adCmdText
.NamedParameters = true
Fix: .Parameters.Append .CreateParameter(prm, adInteger,1, 15, id)
.CommandText = "SELECT ID, FIRST_NAME, LAST_NAME FROM person WHERE ID = ?"
.Parameters.Append prm
End With
set rs = CreateObject("ADODB.Recordset")
set rs.Source = cmdQuery
rs.CursorType = adOpenForwardOnly
rs.LockType = adLockReadOnly
rs.Open
答案 0 :(得分:0)
试试这个
dim id
dim conn
dim cmdQuery
Const adCmdText = 1
Const adOpenForwardOnly = 0
Const adLockReadOnly = 1
Const adVarChar=200
Const adInteger = 3
set conn = server.CreateObject ("ADODB.Connection")
conn.Open "DRIVER={SQL Server};" & _
"SERVER=xxx.xx.x.xxx,xxxx;" & _
"UID=sa;" & _
"PWD=sa;" & _
"DATABASE=person"
id = 1019438
set cmdQuery = CreateObject("ADODB.Command")
Set cmdQuery.ActiveConnection = conn
cmdQuery.CommandType = adCmdText
cmdQuery.NamedParameters = true
cmdQuery.CommandText = "SELECT ID, FIRST_NAME, LAST_NAME FROM person WHERE ID = ?"
cmdQuery.Parameters.Append cmdQuery.CreateParameter("ID", adInteger, 1, 255, Request("person_id"))
set rs = CreateObject("ADODB.Recordset")
set rs.Source = cmdQuery
rs.CursorType = adOpenForwardOnly
rs.LockType = adLockReadOnly
rs.Open