ParameterDirection.ReturnValue用法

SqlCommand mycom = usercommon.createcommand();
         mycom.CommandText = "ModifyUserPwd";
         SqlParameter[] parm ={ new SqlParameter("@username", SqlDbType.VarChar, 50), new SqlParameter("@userpwd", SqlDbType.VarChar, 50), new SqlParameter("@newpwd", SqlDbType.VarChar, 50),new SqlParameter("@returnvalue",SqlDbType.Int) };
         parm[0].Value=username;
         parm[1].Value=oldpwd;
         parm[2].Value=newpwd;
         parm[3].Direction = ParameterDirection.ReturnValue;
         usercommon.AttachParameters(mycom,parm);
         mycom.ExecuteNonQuery();
         int i =(Int32) mycom.Parameters["@returnvalue"].Value;
         usercommon.CloseConn();
         return i;

alter proc ModifyUserPwd
(
@username varchar(50),
@userpwd varchar(50),
@newpwd varchar(50)
)
as
declare @pwd varchar(50)
select @pwd=userpwd from users
if(@pwd=@userpwd)
begin
update users set userpwd=@newpwd where username=@username
return 1
end
else
return 0
go
原文地址:https://www.cnblogs.com/bobo41/p/3097055.html