用户登录权限的问题

noreenxqc111 2017-12-27 11:18:10
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语句啊...
...全文
898 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
夜班机器人 2018-02-07
  • 打赏
  • 举报
回复
if else 太多了 看都看不清. 用switch判断行不
wnmcs 2018-02-02
  • 打赏
  • 举报
回复
一步一步写,不要急!慢慢来! 使用 if elseif elseif end
Anglry 2018-01-10
  • 打赏
  • 举报
回复
看你的代码,你的等级应该是自己填入,先不说这个,你的if只作用于判断管理员,少了是否为空或者是其他等级的

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧