存储过程:
是一个登录界面
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”,单独测试存储过程没问题的!
是一个登录界面
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”,单独测试存储过程没问题的!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货