简单的获取ASP准备语句 [英] Simple fetch ASP prepared statement
问题描述
我已经使用php进行所有操作,但是现在我需要使用ASP在MS SQL中查找某些内容.
I've used php for everything, but now I need to look up something in MS SQL with ASP.
为了上帝的爱,我无法弄清楚如何将post参数绑定到准备好的语句并打印结果.
I cannot for the love of God figure out how to bind post parameters to a prepared statement and print the results.
对于每个查询,我只需要获取一行,其中SQL语句如下所示:
I need to fetch only 1 row for each lookup, where the SQL statement would look like:
选择ID,来自ID =吗?的成员的姓名?
SELECT ID,NAME FROM MEMBERS WHERE ID = ?
从一个例子到我已经了解了很多,并阅读了一些帖子:
I've gotten as far as this, from an example and reading a bit of posts:
Response.Buffer = True
On Error Resume Next
Dim host
Dim port
Dim user
Dim password
Dim database
host = "host"
port = "1433"
user = "user"
password = "pass"
database = "database"
Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
Dim ds
ds = host & "," & port
Dim connString
connString = "Provider=SQLOLEDB;Data Source=" & ds & ";Network Library=DBMSSOCN;Initial Catalog=" & database & ";User Id=" & user & ";Password=" & password & ";"
conn.Open connString
Dim cmdPrep1 As New ADODB.Command
Set cmdPrep1.ActiveConnection = cn
cmdPrep1.CommandText = "SELECT ID,NAME FROM MEMBERS WHERE ID =?"
cmdPrep1.CommandType = adCmdText
cmdPrep1.Prepared = True
我的知识就在这里结束.
This is where my knowledge ends.
我如何将输入参数(POST)绑定到上面并打印获取的行?
How would I bind input paramters (POST) to the above and do a print of the fetched row?
为什么相对于php而言,很难找到基本的ASP示例?对我来说似乎很奇怪.
Why are basic ASP examples so hard to come by vs. php? Seems odd to me.
推荐答案
这在经典的asp中不起作用:
this will not work in classic asp:
Dim cmdPrep1 As New ADODB.Command
您必须像这样使用server.createobject:
you have to use server.createobject like so:
dim cmdPrep1 : set cmdPrep1 = server.createobject("ADODB.Command")
cmdPrep1.ActiveConnection = cn
cmdPrep1.CommandType = adCmdText
cmdPrep1.CommandText = "SELECT ID,NAME FROM MEMBERS WHERE ID =?"
cmdPrep1.parameters.Append cmd.createParameter( "ID", adInteger, , , Request.Form("nameOfIDField") )
dim rs : set rs = cmdPrep1.execute
现在您有一个 ADODB .Recordset 在您的变量rs中.
now you have an ADODB.Recordset in your variable rs.
这篇关于简单的获取ASP准备语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!