用户登录界面验证代码

    protected void Button1_Click(object sender, EventArgs e)
    {
        string connStr = System.Configuration.ConfigurationSettings.AppSettings["connString"];
        SqlConnection myConnection = new SqlConnection(connStr);
        string checkStr = "select count(*) from bbs_register where (username='"+username.Text+"' and pwd='"+password.Text+"')";
        SqlCommand cmd = new SqlCommand(checkStr,myConnection);
        myConnection.Open();
        int flag = (int)cmd.ExecuteScalar();
        myConnection.Close();
        if (flag > 0)
        {
            Session["username"] = username.Text;
            Response.Redirect("show.aspx");
        }
        else
        {
            Label4.Text = "用户名或密码有误,请重新输入!";
            Label4.ForeColor = Color.Red;
        }
    }

posted on 2010-10-24 18:10  Cleak  阅读(718)  评论(0)    收藏  举报

导航