当前位置:K88软件开发文章中心编程语言AspAsp01 → 文章内容

sql存储过程----显示表中的记录

减小字体 增大字体 作者:佚名     来源:asp编程网  发布时间:2018-12-30 8:29:54

利用存储过程显示出表中的记录,如新闻罗列
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 
 
 
 
 
 


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
'表明这是一个存储过程
 
 
 
 
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存储过程----显示表中的记录