protected void btnLogin_Click(object sender, EventArgs e)
{ SqlConnection conn = new SqlConnection("Server = (local);user id = sa;pwd = 1;database = Login");
try
{
conn.Open();
string cmdText = "select username from userinfo where username = '" + this.txtUsername.Text.Trim() + "' and userpassword='" + this.txtPassword.Text.Trim() + "'"; SqlDataAdapter sqlCommon = new SqlDataAdapter(cmdText, conn);
DataSet ds = new DataSet();
sqlCommon.Fill(ds);
if (txtUsername.Text.Trim() == ds.Tables[0].Rows[0][" username"] && txtPassword.Text.Trim() == ds.Tables[0].Rows[0]["userpassword"]) {
conn.Close();
Response.Redirect("Default2.aspx");
}
else
{
lblResults.Visible = true;
lblResults.Text = "用户名或密码错误!";
txtUsername.Text = "";
txtPassword.Text = ""; }
conn.Close();
}
catch (SqlException ex)
{
Console.WriteLine("连接出错" + ex.Message);
}
}
结果是密码错的, lblResults也不会提示,只是txtPassword.Text = "";密码对的也会出现txtPassword.Text = "";而不是转业
{ SqlConnection conn = new SqlConnection("Server = (local);user id = sa;pwd = 1;database = Login");
try
{
conn.Open();
string cmdText = "select username from userinfo where username = '" + this.txtUsername.Text.Trim() + "' and userpassword='" + this.txtPassword.Text.Trim() + "'"; SqlDataAdapter sqlCommon = new SqlDataAdapter(cmdText, conn);
DataSet ds = new DataSet();
sqlCommon.Fill(ds);
if (txtUsername.Text.Trim() == ds.Tables[0].Rows[0][" username"] && txtPassword.Text.Trim() == ds.Tables[0].Rows[0]["userpassword"]) {
conn.Close();
Response.Redirect("Default2.aspx");
}
else
{
lblResults.Visible = true;
lblResults.Text = "用户名或密码错误!";
txtUsername.Text = "";
txtPassword.Text = ""; }
conn.Close();
}
catch (SqlException ex)
{
Console.WriteLine("连接出错" + ex.Message);
}
}
结果是密码错的, lblResults也不会提示,只是txtPassword.Text = "";密码对的也会出现txtPassword.Text = "";而不是转业
在设计模式中无法计算表达式。