我正在开发一个考勤监控系统,我需要员工表格从ms访问中选择具有特定日期的数据,我需要它每天显示不同的数据。例如,最近在这一天计时的10个人,它会选择,但是在第二天它将获取另一批数据
这是我的代码
try
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
DateTime dateTime = dateTimePicker1.Value;
string query = "SELECT FROM TimeinTimeout WHERE InDate=" + String.Format("{0:# MM/dd/yy #}", dateTime);
command.CommandText = query;
OleDbDataAdapter da = new OleDbDataAdapter(command);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.Update();
dataGridView1.Refresh();
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
答案 0 :(得分:0)
这允许用户选择特定日期的所有TimeinTimeout数据的日期
private void button1_Click(object sender, EventArgs e)
{
SqlDataAdapter sdf = new SqlDataAdapter("select * from TimeinTimeout where date'" + dateTimePicker1.Value.ToString() + "'", constring); ;
DataTable sd = new DataTable();
sdf.Fill(sd);
dataGridView1.DataSource = sd;
}