源代码:
SqlConnection con = new SqlConnection("Data Source=ANIRUDH;Initial Catalog=DB1;Integrated Security=True");
con.Open();
protected void Login_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("SELECT * FROM USER_LOGIN WHERE USERID='" + txtUserName.Text + "' AND PASSWORD='" + txtPassword.Text + "'", con);
SqlDataReader dr = cmd.ExecuteReader();
string userid = txtUserName.Text;
string password = txtPassword.Text;
dr.Read();
if((dr["USERID"].ToString() == userid) && (dr["PASSWORD"].ToString() == password))
{
Response.Redirect("/WebForm1.aspx", true);
}
else
{
Response.Write("Invalid");
}
}
问题:
这总是给出......当我输入正确的用户名和密码时,因为它在数据库中......当我使用标签来显示来自数据库的值时......它们正确并显示......但是在比较时总是显示 INVALID