我怎样才能 select 从日期为最后一天的 table 多列?

How can I select multi-column from table where date is last day?

我正在尝试 select 我的 table 日期小于今天的字段。

connect.Open();
command.Connection = connect;
today = DateTime.Today.ToString("dd/MM/yyyy");
string query = "select attendance as [Attend], Emp_UserId as ID, 'Date_ofday' as [Today Date] , Emp_UserName as Name ,Delay_Hours as [Delay Hours] from Attendance where Date_ofday > '"+ DateTime.Parse(today) + "'  ";
command.CommandText = query;
OleDbDataAdapter da1 = new OleDbDataAdapter(command);
DataTable dt1 = new System.Data.DataTable();
da1.Fill(dt1);
dataGridView1.DataSource = dt1;

这会产生 data type missmissing operator 错误,使用的是 Access 数据库。

您正在将 DateTime 转换为字符串,然后在下一行将其解析回 DateTime,这没有意义。我认为你应该使用参数,看看这是否有效,我不使用 MySql:

connect.Open();
command.Connection = connect;
todday = DateTime.Today.ToString("dd/MM/yyyy");
string query = "select attendance as [Attend], Emp_UserId as ID, 'Date_ofday' as [Today Date] , Emp_UserName as Name ,Delay_Hours as [Delay Hours] from Attendance where Date_ofday > @Today";
command.CommandText = query;
OleDbDataAdapter da1 = new OleDbDataAdapter(command);
DataTable dt1 = new System.Data.DataTable();
da1.SelectCommand.Parameters.AddWithValue("@Today", DateTime.Today);
da1.Fill(dt1);
dataGridView1.DataSource = dt1;

如果您使用的是 MS Access,则查询变为:

string query = "select attendance as [Attend], Emp_UserId as ID, 'Date_ofday' as [Today Date] , Emp_UserName as Name ,Delay_Hours as [Delay Hours] from Attendance where Date_ofday > ?";