|
Asp深度揭密(上)(8)
cmd("@sid")=10
cmd.execute()
bbb=cmd("@sid")
response.write bbb&"<br>"
set cmd=nothing
'使用command调用带两个输入参数和返回值的存储过程
'CREATE PROCEDURE [return_1]
'(@user_name varchar(40))
'AS
'if exists(select id from user_info where user_name=@user_name)
'return 1
'else
'return 0
response.write "<br>调用带两个输入参数和返回值的存储过程:<br>"
set cmd=server.createobject("adodb.command")
cmd.activeconnection=conn
cmd.commandtype = adcmdstoredproc
cmd.commandtext = "return_1"
cmd.parameters.append cmd.createparameter("@return_value",adinteger,adparamreturnvalue)
cmd.parameters.append cmd.createparameter("@user_name",advarchar,adparaminput,40)
cmd.parameters.append cmd.createparameter("@password",advarchar,adparaminput,20)
cmd("@user_name")="tuth"
cmd("@password")="yyuyu"
cmd.execute()
rrr=cmd("@return_value")
response.write rrr
set cmd=nothing
conn.close
set conn=nothing
%>
效果:
访问http://10.1.43.238/course/use_proc.asp?user_name=ahyi&password=ttt时,出现如下
普通的调用方法:
12
返回纪录集,可以使用recordcount等属性:
ahyi
tet
tuth
调用带输出参数的存储过程:
2
调用带两个输入参数和返回值的存储过程:
1
注意:若存储过程无参数,则调用的sql语句直接为存储过程名,一个参数为“存储过程名 参数”,若是多个参数,则“存储过程名 参数1,参数2,……,参数n”;如果在sql语句中加入exec,则在返回的记录集中可以使用recordcount等属性;如果想获得存储过程的返回值或输出参数,可以使用command对象。
⑵.使用事务处理
①.Asp内嵌的事务支持
例子:
use_transaction_1.asp
<%
'Asp中使用事务
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "course_dsn","course_user","course_password"
conn.begintrans '开始事务
sql="delete from user_info"
set rs=server.createobject("adodb.recordset")
|