SqlConnection con = new SqlConnection("Data Source=WIN-JKNISFADCO4;Initial Catalog=user;uid=*;pwd=*");
con.Open();
SqlCommand yanzheng = new SqlCommand("select Pwd from [user] where Username='" + TextBox1.Text + "';", con);
string pwd = yanzheng.ExecuteScalar().ToString();
if (pwd == TextBox2.Text)
{
Session["username"] = TextBox1.Text;
Response.Write("密码正确!");
Response.Write(pwd);
Response.Write(TextBox2.Text);
Response.Write("<script>alert('用户登录成功');history.go(-1);</script>");
}
else
{
Response.Write("密码错误!");
Response.Write(pwd);
Response.Write(TextBox2.Text);
}
就是 if (pwd == TextBox2.Text)一直出错不正常啊,就算Pwd和textbox2.text一样的他也判断是不对的,就解释
------解决方案--------------------------------------------------------
先不说其他的,你确认他们两个的值一样,你跟踪了吗,看看是否有空格
------解决方案--------------------------------------------------------
if (pwd.Trim() == TextBox2.Text)
{
Session["username"] = TextBox1.Text;
Response.Write("密码正确!");
Response.Write(pwd);
Response.Write(TextBox2.Text);
Response.Write("<script>alert('用户登录成功');history.go(-1);</script>");
}
pwd有空格,去除
------解决方案--------------------------------------------------------
既然你知道是用Session["username"]!=null来判断是否登录的话,那么你的注销就需要实现Session["username"]= null的嘛!