Jump:
string query = "SELECT * FROM `depositRequests` LIMIT 1";
MySqlCommand cmd = new MySqlCommand(query, connection);
MySqlDataReader reader = cmd.ExecuteReader();
Thread.Sleep(1000);
reader.Read();
Log.Info("Durchlauf: " + i);
if (reader.Read())
{
SteamID SteamAddID = new SteamID(reader.GetString(2));
string authCode = reader.GetString(3);
Log.Info("SteamAddID: " + SteamAddID);
Log.Info("AuthCode: " + authCode);
Bot.log.Success("Add SteamAddID: " + SteamAddID + "AuthCode: " + authCode);
AddFriendForTrade(SteamAddID, authCode);
}
else
{
Bot.log.Warn("No Data found! Waiting for Deposit Request");
Thread.Sleep(60000);
reader.Close();
i++;
goto Jump;
}
那么为什么他总是跳进else路径,尽管数据库中有一个条目?
感谢您的帮助!
答案 0 :(得分:4)
因为您只获得一个记录,然后在此行的if
语句之前阅读它:
Thread.Sleep(1000);
reader.Read(); <---
由于没有第二条记录,您对Read
的第二次通话始终会返回 false 。
您应该删除此行,并在Read
语句中仅调用if
一次,或者存储Read
方法的结果并在if
中使用该变量:
bool isRecordExists = reader.Read();
if(isRecordExists)
{
...
}