C#:检测员工登录密码时出错
对于我输入的每个密码和用户名,都会显示相同的消息“用户名和密码正确”,请帮助我检测不正确的密码C#:检测员工登录密码时出错,c#,C#,对于我输入的每个密码和用户名,都会显示相同的消息“用户名和密码正确”,请帮助我检测不正确的密码 private void btn_Login_Click(object sender, EventArgs e) { connection.Open(); OleDbCommand command= new OleDbCommand(); command.Connection=connection; com
private void btn_Login_Click(object sender, EventArgs e)
{
connection.Open();
OleDbCommand command= new OleDbCommand();
command.Connection=connection;
command.CommandText="Select * from EmployeeData where Username ='"+txt_Username.Text+"' and Password='"+ txt_Password.Text+"'";
OleDbDataReader reader= command.ExecuteReader();
int count=0;
while(reader.Read());
{
count =count+1;
}
if (count == 1)
{
MessageBox.Show("Username and password is correct");
}
else if(count > 0)
{
MessageBox.Show("Username or password is NOT correct");
}
connection.Close();
}
您的密码识别只是查看是否只有一个数据集。函数
reader.Read()
读取下一个数据集。
计算Read
能够读取下一个数据集的频率。然后根据该数字决定密码的有效性
那很可能不是你的主意。在第行中,while(reader.Read())代码>
除去
)
自始至终
while(reader.Read())
{
计数=计数+1;
}
是真的