自己写的一个简单ASP调用存储过程查询

本文用到没有用到adodb.command命令,只是简单的做了一个用adodb.recordset来执行存储过程。

存储过程:
'在SQL中建立dbo.tse存储过程

CREATE PROCEDURE [dbo].[tse]
@keyword varchar(20)=null, '定义查询的关键字
@choose int=null '定义查询的类型(1为查询列title,其他为content)
as
if @choose=1
select * from web where title like @keyword + '%'
else
select * from web where content like @keyword + '%'
return
GO

'list.asp页

 1   
 2dim rs   
 3dim sql   
 4dim keyword   
 5dim choose   
 6keyword=request(“keyword“) '接收页面传送的值   
 7choose=request(“choose“)   
 8set rs=server.createobject("adodb.recordset")   
 9sql="exec tse '"&keyword&"',"&choose&"" '用exec执行tse存储过程,把keyword,choose给存储过程传递参数   
10rs.open sql,conn,1,1   
11if rs.eof and rs.bof then   
12response.write("没有任何记录!")   
13response.end   
14end if   
15response.write"搜索到的记录如下:

<br/>

<br/>

1"   
2do until rs.eof   
3response.write""&rs("id")&":"&rs("title")&"" '打印出文章的ID和标题   
4response.write"

<br/>

<br/>

1"   
2rs.movenext   
3loop   
4'打扫战场   
5rs.close   
6conn.close   
7set rs=nothing   
8set conn = nothing   
Published At
Categories with Web编程
Tagged with
comments powered by Disqus