0

我有 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);
        }
4

2 回答 2

1

您可以Value使用DateTimePicker. 然后,您可以使用AddMinutes, AddDays, 等来增加值。

以下将使用第二天作为结束日期。

DateTime endDate = dateTimePicker2.Value.Date.AddDays(1);
于 2012-09-04T02:50:49.103 回答
0

You can format value custom. Use following.

dateTimePicker2.Format = DateTimePickerFormat.Custom;
dateTimePicker2.CustomFormat = "MMMM dd, yyyy - dddd";

If you want to use SQL query ,you had better to format Date value, like this:

CONVERT(varchar(10) ,dateTimePicker2.text,120) 
于 2012-09-04T03:24:47.027 回答