用户登录权限的问题

时间:2022-05-24 14:46:08
string m_connStr = "Data Source=LENOVO-PC\\MRWWK;Initial Catalog=Book;Persist Security Info=True;User ID=sa;Password=123456";
if (userName.Text == "")
{
Response.Write("用户名不能为空");
userName.Focus();
}
else
if (userPass.Text == "")
{
Response.Write("密码不能为空!");
userPass.Focus();
}
string strSQL = "select * from [User] where User_Account='" + userName.Text + "'  AND User_Pwd='" + userPass.Text + "' User_Role='" + Role.Text + "'";
SqlConnection conn = new SqlConnection(m_connStr);
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter sql = new SqlDataAdapter(strSQL, conn);
sql.Fill(ds);
conn.Close();
if (ds.Tables[0].Rows.Count > 0)
{
if (Role.Text == "管理员")
{
Response.Redirect("Register.aspx");
}
else
{
Response.Redirect("Bookborrow.aspx");
}
}
else
{
Response.Write("用户名或密码错误");
}
}
}
我想判断角色是否正确,例如数据库中小明是管理员那么如果我选择了其他角色就会无法登陆,或是有什么提示....应该怎么写啊,求大神...应该怎么加if语句啊...

2 个解决方案

#1


[看你的代码,你的等级应该是自己填入,先不说这个,你的if只作用于判断管理员,少了是否为空或者是其他等级的, 一步一步写,不要急!慢慢来!
使用 if elseif elseif end]

#1


[看你的代码,你的等级应该是自己填入,先不说这个,你的if只作用于判断管理员,少了是否为空或者是其他等级的, 一步一步写,不要急!慢慢来!
使用 if elseif elseif end]