首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2013-02-15 
求助这段代码的判断哪里出错了。db_User里三个字段username,password,ifadmin,ifadmin表示是否为管理员。T o

求助这段代码的判断哪里出错了。
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


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

热点排行