我有 2 个用于过滤 Access 查询的数据选择器对象。当我运行例如 2012 年 9 月 1 日(开始日期)和 2012 年 9 月 5 日(结束日期)的查询时,它会为我提供从 2012 年 9 月 1 日上午 12 点到 2012 年 9 月 4 日 11:59 的所有内容。有没有办法通过增加结束日期来包括结束日的实际日历日?
这是我的代码:
string startDate = dateTimePicker1.Text;
string endDate = dateTimePicker2.Text;
OleDbCommand command = new OleDbCommand();
command.Parameters.AddWithValue("@startDate", startDate);
command.Parameters.AddWithValue("@endDate", endDate);
try {
command.Connection = connect;
command.CommandText = "SELECT RecordID, TimeStamp, EmployeeName, AreaDescription FROM LoginRecords r, Employees e, Areas a WHERE (e.EmployeeID = r.EmployeeID) AND (a.AreaID = r.AreaID) AND (TimeStamp BETWEEN @startDate AND @endDate) ORDER BY TimeStamp";
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
tw.WriteLine(reader["RecordID"].ToString() + " " + reader["TimeStamp"].ToString() + " " + reader["EmployeeName"].ToString() + " " + reader["AreaDescription"].ToString() + ",");
listBox1.Items.Add(reader["RecordID"].ToString() + " " + reader["TimeStamp"].ToString() + " " + reader["EmployeeName"].ToString() + " " + reader["AreaDescription"].ToString() + ",");
}
}
catch (Exception ex){
MessageBox.Show("Error: " + ex.Message);
}