C#-SQL中的Reader始终返回false

时间:2019-01-28 19:29:46

标签: c# mysql sql

因此,我试图在C#应用程序中创建登录系统,并且我将sql / mysql用于存储用户数据的数据库,并且在执行读取器,然后执行并if语句(如果读者读然后做某事),而if语句总是返回false,我不知道为什么,它没有给出任何异常,我将它放在try语句中,但是也没有异常,所以我真的不知道这是什么错误。连接,查询和其他一切都还可以(我已经仔细检查了),这是我的代码:

if (!OpenConnection(Connection)) return false;
                    using (var cmd =
                    new MySqlCommand(
                        "SELECT Login, Password, HWID, Premium, IP FROM Users WHERE Login = @Login AND Password = @Password" +
                        " AND HWID = @HWID AND Premium = @Premium AND IP = @IP",
                        Connection))
cmd.Parameters.AddWithValue("@Login", username);
                        cmd.Parameters.AddWithValue("@Password",
                        Encryption.Encrypt(password, Encryption.RandomBytes().ToString(), salt));
cmd.Parameters.AddWithValue("@HWID", hardware);
cmd.Parameters.AddWithValue("@Premium", 1);
cmd.Parameters.AddWithValue("@IP", Helpers.GetIpAddress());

var reader = cmd.ExecuteReader(); // < executing the reader everything is ok

if (reader.Read()) // < and then this is where it always returns false no matter what
    {
reader.Close();
Connection.Close();
return true
    }

reader.Close(); // this is where it goes when the reader is returning false
Connection.Close(); // this is where it goes when the reader is returning false
return false; // this is where it goes when the reader is returning false

0 个答案:

没有答案