gpt4 book ai didi

c# - MySQLDataReader 仅在行数较多时循环一次

转载 作者:行者123 更新时间:2023-11-30 00:37:37 27 4
gpt4 key购买 nike

我正在开发一个 C# 项目,目前我遇到了 MySQL 数据读取器的问题。

下面是我正在使用的代码

try
{
using (ConnectMySQLDB db = new ConnectMySQLDB(Configuration.databaseSettings))
{
string query = "SELECT COUNT(*) AS `TotalRows`, reports.id AS `BugID`, DateReported, Software, Platform, Version, FirstName, "
+ "LastName, Email, Summary, BugDescription, PinCode, SendUpdates, Priority, Summary "
+ "FirstName, LastName, Email, Summary, "
+ "bug_updates.id AS `UpdateID`, UpdateMessage FROM reports, software, platforms, versions, bug_updates "
+ "WHERE reports.SoftwareID = software.id AND reports.PlatformID = platforms.id "
+ "AND reports.VersionID = versions.id AND reports.id = 1 AND reports.id = bug_updates.BugID AND SendUpdates=1 "
+ "AND BugUpdateNotificationSent='0'";
using (MySqlCommand cmd = new MySqlCommand(query, db.conn))
{
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
totalEmails = reader.GetInt32("TotalRows");
library.logging(methodInfo, string.Format("Found {0} bugs requiring update notification", totalEmails));
if (totalEmails > 0)
{
currentEmailCount++;
EmailNotifications emailNotifications = new EmailNotifications(reader);
emailNotifications.sendBugReportUpdateEmailNotification(currentEmailCount, totalEmails);
}
else
{
library.logging(methodInfo, "No emails requiring to be sent for update notification");
}
}
}
}
}
}
catch (MySqlException ex)
{
string error = string.Format("Failed to check if updates need to be sent. MySQL Error: {0}", ex.Message);
library.logging(methodInfo, error);
library.setAlarm(error, CommonTasks.AlarmStatus.Medium, methodInfo);
}
catch (Exception ex)
{
string error = string.Format("Failed to check if updates need to be sent. General Error: {0}", ex.Message);
library.logging(methodInfo, error);
library.setAlarm(error, CommonTasks.AlarmStatus.Medium, methodInfo);
}

问题是当我单步执行代码时,它进入循环以在数据读取器上执行读取,总行数设置为 13,因此数据读取器中有 13 行。我成功地完成了循环中的所有内容,但由于某种原因,它退出了循环并且没有遍历其余的行。

感谢您提供的任何帮助。

最佳答案

从查询的外观来看,问题出在 WHERE 子句中。

reports.id = 1 AND reports.id = bug_updates.BugID

我很确定您想要删除 reports.id = 1,因为您已经在过滤 BugID

关于c# - MySQLDataReader 仅在行数较多时循环一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22028210/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com