选择显示字体大小

在asp中使用存储过程

    学习使用存储过程(stored procedure),是asp程序员的必须课之一。所有的大型数据库都支持存储过程,比如oracle、ms sql等,(但ms access不支持,不过,在access里可以使用参数化的查询)。
    使用存储过程有许多好处,它可以封装复杂的数据逻辑,充分发挥大型数据库本身的优势。我们知道,asp并不适合做复杂的数据运算,而通过old db访问数据库,由于数据需要在asp数据库之间传递,相当消耗系统资源。事实上,如果数据库仅仅起着数据存储的作用,那么它的功能是远远没有得到利用的。
    关于如何创建存储过程,请参考ms sql的相关文档。
本文介绍存储过程如何在asp中运用。
简单的一个sql语句:
select id,name,picture,time,duty from employ 
我们可以创建一个存储过程


create procedure sp_employ
as
select id,name,picture,time,duty from employ 
go
 


而sql语句:
select id,name,picture,time,duty from employ where id=10230
对应的存储过程是:(用alter替换我们已有的存储过程)

alter procedure sp_employ
@inid  int
as
select id,name,picture,time,duty from employ  where id=@inid

go
 


下面对比一下sql和存储过程asp中的情况。首先看看直接执行sql的情况:

<%
dim conn, strsql, rs
set conn = server.createobject("adodb.connection")
conn.open  "dsn=webdata;uid=user;pwd=password" 
strsql = " select id,name,picture,time,duty from employ "
set rs = conn.execute(strsql) 
%> 


再看看如何执行stored procedure:

<%
dim conn, strsql, rs
set conn = server.createobject("adodb.connection")
conn.open  "dsn=webdata;uid=user;pwd=password" ’make connection
strsql = "sp_employ"
set rs = conn.execute(strsql) 
%> 


而执行带参数的stored procedure也是相当类似的:

<%
dim conn, strsql, rs, myint
myint = 1 
set conn = server.createobject("adodb.connection")
conn.open  "dsn=webdata;uid=user;pwd=password"
strsql = "sp_mystoredprocedure " & myint
set rs = conn.execute(strsql) 
%> 


你可能觉得在asp中使用存储过程原来是这样的简单。对!就是这么简单。


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons