日期:2014-05-17  浏览次数:20867 次

关于存储过程的问题!请高手进来看看!
我想把下面这些代码用sub封状起来,但是它却包错,说什么缺少cmd,以下是sub中的代码:
sub   csp(csp_name)
set   cmd=server.CreateObject( "adodb.command ")
'指明cmd对象的数据库连接对象
set   cmd.activeconnection=cn
'命令文本
cmd.commandtext= "csp_name "
'指明该文本就为存储过程
cmd.commandtype=4
'刷新并清空参数
cmd.parameters.refresh
'给存储过程里面的参数赋值
end   sub
处理页面的代码是:
<!--#include   file= "conn.asp "-->
<!--#include   file= "func.inc "-->
<%
pwd=request( "pwd ")
username=request( "username ")
'声明一个cmd对象
call   csp( "csp_login ")
cmd.parameters( "@username ").value=username
cmd.parameters( "@pwd ").value=pwd
'执行存储过程
cmd.execute()
Relt=cmd.parameters( "@succed ")
if   Relt= "1 "   then
response.Write( "登陆成功! ")
else
response.Write( "用户名和密码不正确 ")
end   if
%>

------解决方案--------------------
cmd.commandtext= "csp_name "改成
cmd.commandtext=csp_name

cmd是sub的局部变量
以下cmd.parameters( "@username ").value=username
cmd.parameters( "@pwd ").value=pwd
在sub之外,当然不能用
要么把set cmd=server.CreateObject( "adodb.command ") 从sub中拿出来作为全局变量