仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 504|回复: 8
打印 上一主题 下一主题

[学习教程] ASP网站制作之asp 中挪用存贮历程的一些例子.(2)

[复制链接]
海妖 该用户已被删除
跳转到指定楼层
#
发表于 2015-1-16 22:59:31 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
ASP是依赖组件的,能访问数据库的组件好多就有好多种,再有就是你微软的工具可是什么都要收钱的啊!历程WritingaStoredProcedurePartII
ByNathanPond


--------------------------------------------------------------------------------


Thisarticleisacontinuationofmypreviousarticle,WritingaStoredProcedure
Letmestartoutbyfirstcorrecting(orratherupdating)somethingIsaidinmyfirstarticle.IsaidtherethatIwasntawareofawaytoupdateastoredprocedurewithoutdeletingitandrecreatingit.WellnowIam.:-)ThereisanALTERcomandyoucanuse,likethis:

ALTERPROCEDUREsp_myStoredProcedure
AS
......
Go




Thiswilloverwritethestoredprocedurethatwastherewiththenewsetofcommands,butwillkeeppermissions,soitisbetterthandroppingandrecreatingtheprocedure.ManythankstoPedroVera-Perezfore-mailingmewiththisinfo.

AspromisedIamgoingtodiveintomoredetailaboutstoredprocedures.LetmestartoutbyansweringacommonquestionIreceivedviae-mail.Manypeoplewroteaskingifitwaspossible,andifsohowtodoit,tousestoredproceduresdotomorethanselectstatements.Absolutely!!!Anythingthatyoucanaccomplishinasqlstatementcanbeaccomplishedinastoredprocedure,simplybecauseastoredprocedurecanexecutesqlstatements.LetslookatasimpleINSERTexample.

CREATEPROCEDUREsp_myInsert
@FirstNamevarchar(20),
@LastNamevarchar(30)
As
INSERTINTONames(FirstName,LastName)
values(@FirstName,@LastName)
Go




Now,callthisprocedurewiththeparametersanditwillinsertanewrowintotheNamestablewiththeFirstNameandLastNamecolumnsapproiatelyassigned.AndhereisanexampleofhowtocallthisprocedurewithparametersfromanASPpage:

<%
dimdataConn,sSql
dimFirstName,LastName

FirstName="Nathan"
LastName="Pond"

setdataConn=Server.CreateObject("ADODB.Connection")
dataConn.Open"DSN=webData;uid=user;pwd=password"makeconnection

sSql="sp_myInsert"&FirstName&","&LastName&""

dataConn.Execute(sSql)executesqlcall
%>




Remeber,youcanusestoredproceduresforanything,includingUPDATEandDELETEcalls.Justembedasqlstatementintotheprocedure.Noticethattheaboveproceduredoesntreturnanything,soyoudontneedtosetarecordset.ThesamewillbetrueforUPDATEandDELETEcalls.TheonlystatementthatreturnsarecordsetistheSELECTstatement.

Now,justbecausearecordsetisntreturned,itdoesntmeanthattherewontbeareturnvalue.Storedprocedureshavetheabilitytoreturnsinglevalues,notjustrecordsets.Letmeshowyouapracticalexampleofthis.Supposeyouhavealoginonyoursite,theuserentersausernameandpassword,andyouneedtolooktheseupinthedatabase,iftheymatch,thenyouallowtheusertologon,otherwiseyouredirectthemtoanincorrectlogonpage.Withoutastoredproceduresyouwoulddosomethinglikethis:

<%
dimdataConn,sSql,rs

setdataConn=Server.CreateObject("ADODB.Connection")
dataConn.Open"DSN=webData;uid=user;pwd=password"makeconnection

sSql="Select*FromUser_TableWhereUserName="&_
Request.Form("UserName")&"AndPassword="&_
Request.Form("Password")&""

Setrs=dataConn.Execute(sSql)executesqlcall

Ifrs.EOFThen
Redirectuser,incorrectlogin
Response.Redirect"Incorrect.htm"
EndIf

processlogoncode
.............
%>




Nowletslookathowwewouldaccomplishthissametaskusingastoredprocedure.Firstletswritetheprocedure.

CREATEPROCEDUREsp_IsValidLogon
@UserNamevarchar(16),
@Passwordvarchar(16)
As
ifexists(Select*FromUser_Table
WhereUserName=@UserName
And
Password=@Password)
return(1)
else
</p>缺点:安全性不是太差了,还行,只要你充分利用系统自带的工具;唯一缺点就是执行效率慢,如何进行网站优化以后,效果会比较好。
乐观 该用户已被删除
8#
发表于 2015-3-25 10:16:53 | 只看该作者
弱类型造成潜在的出错可能:尽管弱数据类型的编程语言使用起来回方便一些,但相对于它所造成的出错几率是远远得不偿失的。
冷月葬花魂 该用户已被删除
7#
发表于 2015-3-11 09:23:09 | 只看该作者
跟学别的语言一样,先掌握变量,流程控制语句(就是ifwhileselect)等,函数/过程,数组
分手快乐 该用户已被删除
6#
发表于 2015-3-3 03:51:26 | 只看该作者
还有如何才能在最短的时间内学完?我每天可以有效学习2小时,双休日4小时。
只想知道 该用户已被删除
5#
发表于 2015-2-12 17:15:14 | 只看该作者
运用ASP可将VBscript、javascript等脚本语言嵌入到HTML中,便可快速完成网站的应用程序,无需编译,可在服务器端直接执行。容易编写,使用普通的文本编辑器编写,如记事本就可以完成。由脚本在服务器上而不是客户端运行,ASP所使用的脚本语言都在服务端上运行。
谁可相欹 该用户已被删除
地板
发表于 2015-2-5 15:29:47 | 只看该作者
ASP.Net摆脱了以前ASP使用脚本语言来编程的缺点,理论上可以使用任何编程语言包括C++,VB,JS等等,当然,最合适的编程语言还是MS为.NetFrmaework专门推出的C(读csharp),它可以看作是VC和Java的混合体吧。
不帅 该用户已被删除
板凳
发表于 2015-1-28 18:23:10 | 只看该作者
在平时的学习过程中要注意现学现用,注重运用,在掌握了一定的基础知识后,我们可以尝试做一些网页,也许在开始的时候我们可能会遇到很多问题,比如说如何很好的构建基本框架。
飘灵儿 该用户已被删除
沙发
发表于 2015-1-21 17:30:03 | 只看该作者
ASP主要是用好六个对象,其实最主要的是用好其中两个:response和request,就可以随心所欲地控制网页变换和响应用户动作了。
透明 该用户已被删除
楼主
发表于 2015-1-20 07:15:18 | 只看该作者
交流是必要的,不管是生活还是学习我们都要试着去交流,通过交流我们可以学到很多我们自己本身所没有的知识,可以分享别人的经验甚至经历。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-9-29 15:25

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表