asp。net读取存储过程问题(100分)

  • 主题发起人 主题发起人 xddouble
  • 开始时间 开始时间
X

xddouble

Unregistered / Unconfirmed
GUEST, unregistred user!
asp.net代码C#调用下面的存储过程,出现如下错误提示:String[3]: the Size property has an invalid size of 0.
//asp.net代码:
private void userlogin(string sloginname, string sloginpassword)
{
SqlConnection myconnection = new SqlConnection(sqlconnectionstring);
SqlCommand mycommand = new SqlCommand("PM_userlogin", myconnection);
mycommand.CommandType = CommandType.StoredProcedure;
//添加存储过程的参数loginname
SqlParameter parloginname = new SqlParameter("@loginname", SqlDbType.VarChar);
parloginname.Value = sloginname;
mycommand.Parameters.Add(parloginname);
//添加存储过程的参数loginpassword
SqlParameter parloginpassword = new SqlParameter("@loginpassword", SqlDbType.VarChar);
parloginpassword.Value = sloginpassword;
mycommand.Parameters.Add(parloginpassword);
//添加存储过程的参数userid
SqlParameter paruserid = new SqlParameter("@userid",SqlDbType.Int);
paruserid.Direction = ParameterDirection.Output;
mycommand.Parameters.Add(paruserid);
//添加存储过程的参数username
SqlParameter parusername = new SqlParameter("@username", SqlDbType.VarChar);
parusername.Direction = ParameterDirection.Output;
mycommand.Parameters.Add(parusername);
//执行存储过程
try
{
myconnection.Open();
mycommand.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
myconnection.Close();
//返回userid和username

Session["userid"] = paruserid.Value;
Session["username"] = parusername.Value;
Label1.Text = (string)(Session["userid"]);
Label2.Text = (string)(Session["username"]);
}
//存储过程:
CREATE PROCEDURE PM_userlogin
(
@loginname varchar(20),
@loginpassword varchar(20),
@userid int output,
@username varchar(20) output
)
AS
if exists(select * from C_User where (UserLoginName = @loginname) and (UserLoginPassword = @loginpassword))
begin
select @username=UserName,@userid = UserID from C_User
where (UserLoginName = @loginname) and (UserLoginPassword = @loginpassword)
end
else
begin
set @userid = 0
set @username='nouser'
end
GO
 
在些处加两行:
begin
set @userid = 0
set @username='nouser'
end
return @userid
只能返回为整数型的数值。
 
后退
顶部