正文

sql存储过程----显示表中的记录2007-10-26 07:22:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/wangsdong/30500.html

分享到:

利用存储过程显示出表中的记录,如新闻罗列
1、数据库和字段见
http://www.programfan.com/blog/article.asp?id=30476

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文件,就可以看到内容了
原创文件,转载请注明来源,作者。

阅读(3242) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册