读书人

这段代码的判断哪里出错了

发布时间: 2013-02-15 15:46:56 作者: rapoo

求助这段代码的判断哪里出错了。
db_User里三个字段username,password,ifadmin,ifadmin表示是否为管理员。T or F
下面判断如果为true,则跳转到loginAdmin.aspx
否则loginNormal.asp

调试的时候全跳转到了loginNormal.asp。求助。
--------------------分线线---------------------------------------------


protected void Button1_Click(object sender, EventArgs e)
{
string str = "select username,password,ifadmin from db_User where username='" + TextBox1.Text + "'";
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
con.Open();
cmd.CommandText = str;
SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);

if (dr.Read())
{
if (dr["password"].ToString() == TextBox2.Text)
{
if (dr["ifadmin"].ToString() == "true")
{
Response.Redirect("LoginAdmin.aspx");
}
else
{
Response.Redirect("LoginNormal.aspx");
}
}
else
{
Response.Write(@"<script>alert('密码输入错误')</script>");
}
}

else
{
Response.Write(@"<script>alert('对不起没有该用户名')</script>");
}
}
[解决办法]
Response.Redirect("LoginAdmin.aspx",true);

Response.Redirect("LoginAdmin.aspx");
return

[解决办法]
if (dr["ifadmin"].ToString() == "True"),看看是大写的True还是小写的true


[解决办法]
楼主该结帖了

读书人网 >asp.net

热点推荐