为什么我的登录表单允许用户使用正确的用户名登录,但密码不正确?


private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(Sqlconnection.connectionString);
SqlCommand cmd = new SqlCommand("select * from tbllogin where @username='" + txtname.Text + "' and @password='" + txtpass.Text + "'");
cmd.Parameters.AddWithValue("@username", txtname.Text);
cmd.Parameters.AddWithValue("@password", txtpass.Text);
cmd.Connection = con;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
MessageBox.Show("Login  Successfully. ..!");
main m = new main();
this.Hide();
m.Show();
}
else
{
MessageBox.Show("Login Failed....!");
}
con.Close();
}

检查您的SELECT语句:

SqlCommand cmd = new SqlCommand("select * from tbllogin where username=@username and password=@password");

相关内容

  • 没有找到相关文章