资源描述:
《asp调用带输出参数存储过程的经典例子》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、asp调用带输出参数存储过程的经典例子 发表时间:2003-1-7 <%@LANGUAGE=VBScript%><%FunctionCheckStrInput(theString) '处理要输入sql语句的
3、字符串 CheckStrInput=Trim(theString) IfIsNull(theString)OrisEmpty(theString)ThenExitFunction CheckStrInput=Replace(CheckStrInput,"'","''") CheckStrInput=Replace(CheckStrInput,"--","") CheckStrInput=Replace(CheckStrInput,"<","<") CheckStrInput=Replace(CheckStrInput,">",">"
4、) CheckStrInput=Replace(CheckStrInput,Chr(34),Chr(34)&Chr(34))EndFunctionifrequest.ServerVariables("REQUEST_METHOD")="POST"then'如果提交表单setconn=server.CreateObject("adodb.connection")setcmd=server.CreateObject("adodb.command")conn.Open"PROVIDER=SQLOLEDB.1;PersistSecurityInfo=True;Us
5、erID=sa;Password=sa;InitialCatalog=TRK2003;DataSource=KVI;ConnectTimeout=1000"setcmd.ActiveConnection=connadCmdSPStoredProc=4 '变量必须声名adParamReturnValue=4adParaminput=1adParamOutput=2adInteger=3adVarChar=200adVarWChar=202cmd.CommandText="addperson" '存储过程名称 '说明:如
6、果该存储过程addperson没有输出参数@id,则上面的cmd.CommandText就可以这样写'cmd.CommandText="addperson"&CheckStrInput(request.Form("realname"))&","&CheckStrInput(request.Form("memo"))'然后直接执行cmd.Execute(),就省略了以下很多的cmd.Parameters.Appendcmd.CommandType=adCmdSPStoredProc '类型为4cmd.Parameters.Appendcmd.CreatePa
7、rameter("@return_value",adInteger,adParamReturnValue)'定义返回变量cmd.Parameters.Appendcmd.CreateParameter("@realname",adVarChar,adParamInput,50,CheckStrInput(request.Form("realname")))cmd.Parameters.Appendcmd.CreateParameter("@memo",adVarWChar,adParamInput,4000,CheckStrInput(request.For
8、m("memo"))) 'Nvarchar型cmd