我有以下代码,
OleDbCommand cmd = new OleDbCommand("SELECT * FROM Users WHERE username = ? AND password = ?",conn);
OleDbParameter p1 = new OleDbParameter();
OleDbParameter p2 = new OleDbParameter();
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
p1.Value = usernametb.Text;
p2.Value = passwordtb.Text;
conn.Open();
OleDbDataReader read = cmd.ExecuteReader();
if (read.Read() == true)
{
conn.Close();
MessageBox.Show("Successfully logged in!");
}
else
{
conn.Close();
MessageBox.Show("Login failed");
}
如果用户有密码,此代码对我有用,但如果用户没有密码,那么它会失败,我不知道为什么。
我哪里错了?