create PROCEDURE personlogin 
@userid varchar(100),
@password varchar(500),@usertype char(2) output,
@regid int output,
@pemail varchar(100) output
AS begin 
select 
@regid=regid,
@usertype=usertype,
@pemail=email
from registerinfo 
 
where userid=@userid 
and [password]=@password  
end 
begin
if @@rowcount<1
   select @regid=0
   select @usertype=''
end
``````````````````````````````````````````````````````````exec personlogin temp,temp
其中temp,是表中的值服务器: 消息 201,级别 16,状态 4,过程 personlogin,行 0
过程 'personlogin' 需要参数 '@usertype',但未提供该参数。

解决方案 »

  1.   

    @usertype是存储过程执行后输出的参数,而你却在执行存储过程的时候就使用这个参数,这个时候的输出参数还没有形成,当然会要求你提供该参数了。
    而另外一个输出参数@regid之所以没有报错,是因为你在使用打印的时候给它赋值了
      

  2.   

    SqlParameter myParameter = new SqlParameter("@usertype", SqlDbType.Char(2));
    myParameter.Direction = ParameterDirection.Output;
    在调用之前要提供这个参数
      

  3.   

    又不是说你定义为OUTPUT类型了,就不用输入此参数。
    OUTPUT是为了给外面取参数用。
    你要想不输入参数,就用缺省参数好了。比如@regid int=0 output
      

  4.   

    不行啊
    大家看一下下面这个存储过程
    create proc login
    @username char(100),
    @state char(2) output
    as 
      
      if exists(select * from registerinfo where userid=@username)
         select @state='1'
      else
        select @state='0'```````````````````````````````
    运行后
    exec login temp结果:
    服务器: 消息 201,级别 16,状态 4,过程 login,行 0
    过程 'login' 需要参数 '@state',但未提供该参数。
      

  5.   

    是的
    可我在asp.net中怎么来运行它?
      

  6.   

    无论in还是out肯定都是需要传递的。out参数使用方法和in差不多,
    你可以事先传递一个初始值就可以了。
    比如:1,-1,或者0什么的。