自己写的一个简单ASP调用存储过程查询
敬业的IT人
互联网
佚名
2008-2-28 0:28:53
本文用到没有用到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页
<!--#include file="conn.inc" -->
<%
dim rs
dim sql
dim keyword
dim choose
keyword=request(“keyword“) '接收页面传送的值
choose=request(“choose“)
set rs=server.createobject("adodb.recordset")
sql="exec tse '"&keyword&"',"&choose&"" '用exec执行tse存储过程,把keyword,choose给存储过程传递参数
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write("没有任何记录!")
response.end
end if
response.write"搜索到的记录如下:<br><br>"
do until rs.eof
response.write""&rs("id")&":"&rs("title")&"" '打印出文章的ID和标题
response.write"<br><br>"
rs.movenext
loop
'打扫战场
rs.close
conn.close
set rs=nothing
set conn = nothing
%>
存储过程:
在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页
<!--#include file="conn.inc" -->
<%
dim rs
dim sql
dim keyword
dim choose
keyword=request(“keyword“) '接收页面传送的值
choose=request(“choose“)
set rs=server.createobject("adodb.recordset")
sql="exec tse '"&keyword&"',"&choose&"" '用exec执行tse存储过程,把keyword,choose给存储过程传递参数
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write("没有任何记录!")
response.end
end if
response.write"搜索到的记录如下:<br><br>"
do until rs.eof
response.write""&rs("id")&":"&rs("title")&"" '打印出文章的ID和标题
response.write"<br><br>"
rs.movenext
loop
'打扫战场
rs.close
conn.close
set rs=nothing
set conn = nothing
%>
- 最新文章
- asp中使用存储过程[02-28]
- 一些不长见的ASP调用存储过程的技巧[02-28]
- SQL Server 2000的安全配置[02-28]
- 一个将数据分页的存储过程[02-28]
- 使用SQL存储过程要特别注意的问题-注意顺序读取[02-28]
- 新手宝典:SQL Server的几个安全问题[02-28]
- 相关文章
- asp中使用存储过程[02-28]
- 一些不长见的ASP调用存储过程的技巧[02-28]
- 用ASP调用存储过程返回临时表记录集的一个示例代码[02-28]
- VS2005+SQL2005 ASP.NET2.0数据库连接[02-27]
- 巧用SQL-DMO创建备份及校验的ASP应用[02-27]
- 解析SQL server与asp 互操作的时间处理[02-27]
