我有一个datagridview,其中包含bio_id和电子邮件。我正在迭代datagridview以根据bio_id和日期获取员工的时间记录。如果我在MySql本身中创建一个MySql语法,它会获得正确的值,但是当我使用MySqlDataReader时,它会给我一个空值。以下是代码:
public MySqlDataReader SendTimeLogs(string fromDate, string toDate, int bioId)
{
using (var cn = new DatabaseConnection().ConnectToMySql())
{
const string query = @"SELECT MIN(scan_time) as 'Time In', MAX(scan_time) as 'Time Out',
TIMEDIFF(MAX(scan_time),MIN(scan_time)) as difference
FROM `filtered_dates`
WHERE bio_id = @bioId AND date BETWEEN @fromDate AND @toDate GROUP BY date ORDER BY date asc";
var cmd = new MySqlCommand(query, cn);
cn.Open();
cmd.Parameters.AddWithValue("@fromDate", fromDate);
cmd.Parameters.AddWithValue("@toDate", toDate);
cmd.Parameters.AddWithValue("@bioId", bioId);
return cmd.ExecuteReader();
}
}
private void SendEmail()
{
var rdr = new EmployeeDataAccess().GetBioIdEmail();
while (rdr.HasRows && rdr.Read())
{
dgvBioIdList.Rows.Add(rdr["bio_id"].ToString(), rdr["email_add"].ToString());
}
for (var i = 0; i < dgvBioIdList.Rows.Count; i++)
{
var message = "Time Logs for Bio ID: " +dgvBioIdList.Rows[i].Cells[0].Value;
var x = new FilteredDatesDataAccess();
var timeLogs = x.SendTimeLogs(dtpStart.Text, dtpStop.Text,
Convert.ToInt32(dgvBioIdList.Rows[i].Cells[0].Value));
var rec = dgvBioIdList.Rows[0].Cells[1].Value.ToString();
Console.WriteLine(message);
Console.WriteLine(rec);
while (timeLogs.HasRows && timeLogs.Read())
{
Console.WriteLine(timeLogs["Time In"] + @" - " + timeLogs["Time Out"]);
}
}
}
我得到Console.WriteLine(消息);和Console.WriteLine(rec);很好但我的while循环没有写在控制台中。你能帮我吗?谢谢。