这是我做的一个登陆操作 从数据库中查询数据 对比后 判别能否登陆
但不知道为什么 不输出任何提示了 请高手指教一下...protected void Button1_Click1(object sender, EventArgs e)    //登陆操作
    {
        //OleDbConnection conn = null;
        string connectonstring = "Data Source=20100508-1714;Initial Catalog=user_regedit;Integrated Security=True";
        //connectonstring += System.Web.HttpContext.Current.Server.MapPath("use.mdb");
        SqlConnection   conn = new SqlConnection(connectonstring);
        conn.Open();
        string sql1 = "select name from user_imformation where (name='" + TextBox_name.Text.Trim() + "')";
        string sql2 = "select pass from user_imformation where (name='" + TextBox_name.Text.Trim() + "')";
        SqlCommand  obj1 = new SqlCommand(sql1, conn);
        try
        {
            object obj_name = obj1.ExecuteScalar();
            if (TextBox_name.Text.Trim() == obj_name.ToString() && TextBox_name.Text != "")
            {
                SqlCommand obj2 = new SqlCommand(sql2, conn);
                try
                {
                    object obj_password = obj2.ExecuteScalar();
                    if (TextBox_password.Text.Trim() == obj_password.ToString() && TextBox_password.Text != "")
                    {
                        Label_msg.Text = "恭喜登陆成功!";
                        Label_name.Text = "";
                        Label_password.Text = "";
                    }
                    else
                    {
                        Label_password.Text = "密码错误";
                        Label_name.Text = "";
                        Label_msg.Text = "";
                    }
                }
                catch (Exception)
                {
                    Label_name.Text = "";
                    TextBox_name.Text = "";
                    TextBox_password.Text = "";
                    Label_msg.Text = "";
                    Label_password.Text = "密码错误";                }            }
        }
        catch (Exception)
        {
            Label_name.Text = "用户名错误!";
            TextBox_name.Text = "";
            TextBox_password.Text = "";
            Label_msg.Text = "";
            Label_password.Text = "";        }
        finally
        {
            conn.Close();
        }    }

解决方案 »

  1.   

    你这个写的也太麻烦了,不过还是能实现你要的功能,
    Label_password.Text ,Label_msg.Text 这两个控件有没有设置为隐藏属性,  最简单的办法,你调试,一步步跟踪,就知道走到哪去了。 
      

  2.   

    大哥。。你断点吧。第一个if语句里面的可能都没走,怎么会有反应。object obj_name = obj1.ExecuteScalar();
      看看obj_name到底是什么?   返回第一行第一列,如果你name前面有id列,它就是返回id,无论你查没查id......
    再者。这段代码逻辑还有问题。怎么能把用户名跟密码分开那这样走下去,只要有用户名对应的一列。。再有密码对应的一列。都能进去无论用户名跟密码是不是在一行