此文章主要向大家讲述的是用ASP对SQL Server存储过程进行调用的实际操作流程,我们主要是以其实际应用代码的方式来引出ASP对SQL Server存储过程进行调用的实际操作流程,以下就是文章的主要内容讲述。
调用代码:
程序代码
- dim account,oldname,newname,RsCommand
- dim adCmdStoredProc,adInteger,adChar,adParamInput,adParamOutput,ReturnValue
- account = session("whoami")
- oldname = trim(Request.Form("oldname"))
- newname = trim(Request.Form("newname"))
- adCmdStoredProc = 4
- adInteger = 3
- adChar = 129
- adParamInput = 1
- adParamOutput = 2
'建立COMMAND对象
- set RsCommand = Server.CreateObject("adodb.command")
- RsCommand.CommandText = "sp_addModify13SName"
- RsCommand.ActiveConnection = conn
- RsCommand.CommandType = adCmdStoredProc
'添加参数
- RsCommand.Parameters.Append RsCommand.CreateParameter("@account", adChar, adParamInput,20,account)
- RsCommand.Parameters.Append RsCommand.CreateParameter("@oldname", adChar, adParamInput,20,oldname)
- RsCommand.Parameters.Append RsCommand.CreateParameter("@newname", adChar, adParamInput,20,newname)
- RsCommand.Parameters.Append RsCommand.CreateParameter("@ReturnValue",adInteger, adParamOutput,4)
- RsCommand.execute'执行
- ReturnValue = RsCommand.Parameters("@ReturnValue")'取出返回值
ASP调用SQL Server存储过程代码:
程序代码
- Create proc sp_addstorename
- ( @account char(20),
- @oldname char(20),
- @newname char(20),
- @ReturnValue int
- )
返回1正常
返回0插入失败
返回9系统错误
- as
- Begin
- set @ReturnValue = 0
- insert into modifyname13(account,oldname,newname) values(@account,@oldname,@newname)
- if @@error > 0
- Begin
- rollback
- set @ReturnValue = 9
- End
- else
- set @ReturnValue = 1
- End
以上的相关内容就是对ASP调用SQL Server存储过程的介绍,望你能有所收获。