100分求解如下程序调用存储过程
前台登陆LOGIN.ASPX
用户名:txtUserName
密码:txtUserPass
数据库中结构:
uid ===表自增字段
UserName ===用户名 ===varchar(50)
UserPass ===密码 ===varchar(50)
Flag ===是否通过(默认是0,也就是被锁定的用户,不能登陆,1是正常,可以登陆) ==int类型
存储过程如下(网上找来的,语法检查通过)
-1-用户不存在,-2-密码错误,-3-此帐号被锁
CREATE PROCEDURE tp_login
@txtUserName varchar(50),
@txtUserPass varchar(50),
@out varchar(50)
AS
declare @key int
set @key=0/* 0-此帐号被锁*/
if not exists(select * from UserList where UserName=@txtUserName)
begin
set @out=-1
return @out
end
else
begin
if not exists(select * from UserList where UserName=@txtUserName and UserPass=@txtUserPass)
begin
set @out=-2
return @out
end
else
begin
if exists(select * from UserList where UserName=@txtUserName and UserPass=@txtUserPass and Flag=@key)
begin
set @out=-3
return @out
end
else
select @out=uid from UserList where UserName=@txtUserName and UserPass=@txtUserPass
return @out
end
end
GO
LOGIN.ASP.CS文件中,如何调用该存储过程?
我是这样写的,但写到那里写不下去了,不会写了,望大哥们帮忙
string txtUserName = Request.Form[ "txtUserName "].ToString().Trim();
string txtUserPass = Request.Form[ "txtUserPass "].ToString().Trim();
SqlConnection conn=GlassDB.createConnection();
conn.Open();
SqlCommand cmd=new SqlCommand( "tp_login ",conn);
cmd.CommandType=CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter( "@txtUserName ",txtUserName));
cmd.Parameters.Add(new SqlParameter( "@txtUserPass ",txtUserPass));
cmd.ExecuteNonQuery();
.......这里怎么返回给用户登陆的信息??上面写的对还是不对啊?
------解决方案-------------------- cmd.Parameters.Add(new SqlParameter( "@txtUserPass ",txtUserPass));
SqlParameter parter = new SqlParameter( "@pageCount ",SqlDbType.VarChar,50);
parter.Direction = ParameterDirection.Output;
cmd.Parameters.Add(parter);
cmd.ExecuteNonQuery();
string outID = parter.Value;
------解决方案--------------------string ReturnValue = " ";
cmd.Parameters.Add(new SqlParameter( "@out ",ReturnValue,ParameterDirection.Output));
------解决方案--------------------在查询分析器里面执行
declare @tmp varchar(50)
exec @tmp=tp_login 参数1,参数2,参数3
你就明白了
或者直接设置output参数
------解决方案--------------------给你看个例子:http://www.5d.cn/Tutorial/webdevelop/.net/200412/1960.html
------解决方案--------------------
------解决方案--------------------up~~~~~~~~~~~~
------解决方案--------------------前面没有测试,有些笔误,现在下班了,仔细看了一下: