- ·上一篇文章:sql存储过程----删除表中的所有记录
- ·下一篇文章:asp网站实现防小偷抓取的策略和方法
sql存储过程----显示表中的记录
利用存储过程显示出表中的记录,如新闻罗列
1、数据库和字段见
http://www.K88.NET/tech/showtech.asp?id=2
2、存储过程代码
 
CREATE 
PROCEDURE 
dbo.getUserList
 
 
 
 
as
 
 
 
 
set 
nocount 
on
 
 
 
 
begin
 
 
 
 
 
 
 
select 
top 
10 
* 
from 
dbo.[user]
 
 
 
 
end
GO
3、conn.asp
<
%
Set 
conn 
= 
Server.CreateObject("ADODB.Connection")
DSNtemp="DRIVER=
{SQL 
Server}
SERVER=(local)
UID=user
PWD=123456
DATABASE=user"
conn.open 
DSNtemp
%>
4、显示记录list.asp
<
!--
#include 
file="conn.asp"-->
<
%
 
 
 
 
'**通过Command对象调用存储过程**
 
 
 
 
DIM 
MyComm
 
 
 
 
Set 
MyComm 
= 
Server.CreateObject("ADODB.Command")
 
 
 
 
MyComm.ActiveConnection 
= 
conn 
 
 
 
 
 
 
 
 
 
'conn是数据库连接字串
 
 
 
 
MyComm.CommandText 
 
 
 
 
 
= 
"getUserList" 
 
 
 
 
'指定存储过程名
 
 
 
 
MyComm.CommandType 
 
 
 
 
 
= 
4 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
'表明这是一个存储过程
 
 
 
 
MyComm.Prepared 
 
 
 
 
 
 
 
 
= 
true 
 
 
 
 
 
 
 
 
 
 
 
 
 
'要求将SQL命令先行编译
 
 
 
 
Set 
rs 
= 
MyComm.Execute
 
Do 
While 
Not 
rs.eof
 
response.write 
rs("y_id")&
":"&
rs("y_username")&
"----"&
rs("y_password")&
"<
br>
" 
'显示记录
 
rs.movenext
 
Loop
 
rs.close
 
 
 
 
Set 
MyComm 
= 
Nothing
%>
5、完成,运行list.asp文件,就可以看到内容了
原创文件,转载请注明来源,作者。
sql存储过程----显示表中的记录