我正在尝试使用会话登录但是出了点问题。它无法从数据库中获取值以进行登录。请检查代码并帮助我。
每当我执行代码时,它都不会进入if
。数据库名称为Session
,表名为login
。
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=THIRD-I;Initial Catalog=Session;Integrated Security=True;");
conn.Open();
string query = "Select Count(*) From login Where user='" + txtuser.Text + "' and password='"+txtpass.Text+"'";
SqlCommand cmd = new SqlCommand(query, conn);
string output = cmd.ExecuteScalar().ToString();
if (output == "1")
{
Session["user"] = txtuser.Text;
Response.Redirect("Login.aspx");
}
else
Label3.Visible = true;
}
}