Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#:检测员工登录密码时出错_C# - Fatal编程技术网

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;
}
是真的