如何使用存储过程检查每一行 [英] how to check each row using stored procedure
本文介绍了如何使用存储过程检查每一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我只在存储过程中传递了两个参数(即用户名和密码),但是在这里我要检查用户是管理员还是注册用户,为此在表中我有一个单独的列,名为"user_group" ...那么如何我可以检查哪个用户属于哪个组.
帮帮我..
在此先感谢..
这是我的存储过程
hello all,
I''m passing only two parameters in stored procedure (i.e username and password), but here I want to check whether the user is admin or registered user, for that in table I have separate column named "user_group"... so how can I check that which user is belonging to which group.??
help me out..
thanks in advance..
this is my stored procedure
ALTER PROCEDURE dbo.LogInProcedure
@username nvarchar (50),
@password nvarchar (50)
AS
SET NOCOUNT ON;
SELECT user_username, user_password
FROM users WHERE user_username=@username AND user_password=@password
这就是该存储过程的执行
and this is the execution of this stored procedure
SqlCommand cmd = new SqlCommand("LogInProcedure", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@username", usernametxt.Text);
cmd.Parameters.AddWithValue("@password", passwordtxt.Text);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
reader.Read();
if (reader.HasRows)
{
Session["uname"] = usernametxt.Text;
Response.Redirect("Home.aspx");
}
else
{
loginerrorpanel.Visible = true;
}
推荐答案
您知道吗,user_grp中为管理员指定的优先级是什么?..
我想您会知道优先顺序的.
然后首先在您的sp中使用
检查用户名和密码是否存在
如果存在(您的查询)
然后,
声明您数据类型的变量,并为相应的密码和用户名传递usergrp.
如果usergrp与管理员优先级相同.则获取诸如任何数据类型数据之类的值作为输出参数.并在代码隐藏中检查该参数,然后重定向到所需的页面.
do you know ,what is the priority given for the admin in user_grp?..
I think You will be knowing the priority.
then initially in your sp check the presence of the username and password using
if exists(your query)
then,
declare a variable of your datatype and pass the usergrp for respective password and username.
if the usergrp is same as admin priority..then get the value such as any datatype-data..as output Parameter.and check the parameter in codebehind and then redirect to required page.
这篇关于如何使用存储过程检查每一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文