ASP怎样访问带多个参数存储过程的代码

时间:2021-04-16

  1.ACCESS

  查询(query_info):

select * from info where stu = name1 and age = age1

  ASP代码:

Dim conn,comm,rs
Set conn = Server.CreateObject("ADODB.Connection")
Set comm = Server.CreateObject("ADODB.Command")
conn.open "Driver={Microsoft Access Driver (*.mdb)};Dbq=" & Server.MapPath("db1.mdb")
comm.Parameters.Append comm.CreateParameter("name1",200,1,100,"张三")
comm.Parameters.Append comm.CreateParameter("age1",200,1,100,"25")
comm.ActiveConnection = conn
comm.CommandType = 4
comm.CommandText = "query_info"
Set rs = comm.Execute
If not rs.eof Then
Response.Write(rs(1))
End if
Set rs = nothing
Set comm = nothing
conn.close
Set conn = nothing

  2.SQL Server:

  存储过程(query_info):

Create PROCEDURE query_info
@name1 varchar(20) ="张三",
@age1 int = 25
AS
Select * from info where stu=@name1 and age = @age1
GO

  ASP代码:

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.open "Driver={SQL Server};server=(local);uid=sa;pwd=txwl006;database=tempdb;"
Set objComm = Server.CreateObject("adodb.command")
objComm.Parameters.append objComm.CreateParameter("@name1",200,1,50,"李四")
objComm.Parameters.append objComm.CreateParameter("@age1",200,1,50,32)
objComm.CommandType = 4
objComm.ActiveConnection = objConn
objComm.CommandText = "query_info"
Set objRs = objComm.execute
If not objRs.eof Then
Response.write objRs(1)
End if
Set objRs = Nothing
Set objComm = Nothing
objConn.close
Set objConn = nothing

  以前在ASP教程上看存储过程的例子都只讲一个参数,当时就想如果有两个或多个参数怎么办?原来这么简单,呵呵。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章