急!!!--存储过程的返回值,不对! 附代码

shaying 2005-05-01 10:14:07
存储过程:
是一个登录界面
userid主键

--处理用户登录事件
CREATE proc sm_login_user
@userid bigint output,
@username varchar(50) output,
@pwd varchar(50),
@type varchar(50)

As
begin
select
@userid=UserID,
@username=UserName
from
Users
where
UserName=@username and Password=@pwd and Type=@type
--如果用户未注册
if @@ROWCOUNT<1
select @username='null'
--print @userid
--print @username
end
GO

调用过程:

public class UserDetails
{
public Int32 UserID;
public string UserName;
public string Password;
public string Type;
}

public UserDetails UserLogin(string username,string pwd,string type)
{
SqlConnection myConnection =
new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand myCommand = new SqlCommand("sm_login_user",myConnection);

myCommand.CommandType = CommandType.StoredProcedure;

SqlParameter prmUserID = new SqlParameter("@userid",SqlDbType.BigInt);
prmUserID.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(prmUserID);

SqlParameter prmUserName = new SqlParameter("@username",SqlDbType.VarChar,50);
prmUserName.Direction = ParameterDirection.Output;
myCommand.Parameters.Add(prmUserName);

SqlParameter prmPassword = new SqlParameter("@pwd",SqlDbType.VarChar,50);
prmPassword.Value = pwd;
myCommand.Parameters.Add(prmPassword);

SqlParameter prmType = new SqlParameter("@type",SqlDbType.VarChar,50);
prmType.Value = type;
myCommand.Parameters.Add(prmType);

UserDetails myUserDetails = new UserDetails();

myUserDetails.UserID = Convert.ToInt32(prmUserID.Value);
myUserDetails.UserName = prmUserName.Value.ToString();
--------------------------------------------------------------------------------------
为什么输入正确的UserName,Password,Type,存储过程返回的值也是:myUserDetails.UserID无值,
myUserDetails.UserName=“null”,单独测试存储过程没问题的!
...全文
142 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
baituole 2005-05-01
  • 打赏
  • 举报
回复
up坐沙发的,输出参数怎么可以当输入参数里
shaying 2005-05-01
  • 打赏
  • 举报
回复
谢谢,不过单独测试存储过程没问题,print输出正确
singlepine 2005-05-01
  • 打赏
  • 举报
回复
SqlDbType.BigInt,太大了吧,换成SqlDbType.Int试试
YAOHE 2005-05-01
  • 打赏
  • 举报
回复
UserName=@username 有问题吧,你多定义变量试试

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧