我通过以下参数化查询进行数据库调用。
set recordset = Server.CReateObject("ADODB.Recordset")
set cmd1 = Server.CreateObject("ADODB.Command")
cmd1.CommandText = "SELECT * FROM tbl_catmaster where (catname =? or catname =?) ORDER BY catname"
cmd1.ActiveConnection = Conn //connection object already created
cmd1.Parameters(0) = "programmer"
cmd1.Parameters(1) = "developer"
set recordset = cmd1.Execute
我的问题是,当我在sql server profiler中看到查询时,它就像:
"Select catname,catname FROM tbl_catmaster"
请帮忙。我正在使用sql server 2005。
答案 0 :(得分:0)
我会这样做:
function commandCreateText(conn, sql)
dim recordset, cmd1
set cmd1 = server.createobject("adodb.command")
set recordset = server.createobject("adodb.recordset")
set cmd1.activeconnection = conn //which you already have defined
cmd1.commandtext = sql
cmd1.commandtype = 1
set commandCreateText = cmd1
end function
sql = "select * from tbl_catmaster where catname = ? or catname = ? order by catname"
set cmd1 = commandCreateText(conn, sql)
set recordset = cmd1.execute(, array("programmer", "developer"))
if recordset.eof then
response.write("No records found!")
else
do until recordset.eof
response.write("1 record found!")
recordset.movenext
loop
end if
答案 1 :(得分:0)
您需要创建和附加参数,不确定探查器。
set prm = cmd1.CreateParameter("@prm", 200, 1,200 , "developer")
cmd1.Parameters.Append prm