如何检查我从日期时间选择器中选择的日期是否大于我的SQL数据库中的日期 [英] How to check if the date I select from date time picker is bigger then the date from my SQL database
本文介绍了如何检查我从日期时间选择器中选择的日期是否大于我的SQL数据库中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void btn_search_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=......;Initial Catalog=Innux;Persist");
conn.Open();
SqlDataAdapter SDA = new SqlDataAdapter("select dbo.Alteracoes.Data, dbo.Funcionarios.numero as no, dbo.Funcionarios.nome, DATEPART(hour, Falta) AS faltas, DATEPART(hour, Coluna2) AS horasextra from dbo.Alteracoes inner join dbo.Funcionarios on dbo.Alteracoes.IDFuncionario = dbo.Funcionarios.IDFuncionario inner join dbo.Departamentos on dbo.Funcionarios.IDDepartamento = dbo.Departamentos.IDDepartamento WHERE Data = '" + dateTimePicker1.Value.ToString("yyyy/MM/dd") + "'", conn);
DataSet dt = new DataSet();
SDA.Fill(dt, "dbo.Alteracoes.Data");
dataGridView1.DataSource = dt.Tables["dbo.Alteracoes.Data"];
conn.Close();
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
}
This code search for the data from the date i choose.
And now i just want cheack if the date selected is < from (select u_recpica from e_industrial.dbo.e1) this table. If true show the data, if not is not valid
我尝试过:
What I have tried:
<pre>
private void btn_search_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=......;Initial Catalog=Innux;Persist");
conn.Open();
SqlDataAdapter SDA = new SqlDataAdapter("select dbo.Alteracoes.Data, dbo.Funcionarios.numero as no, dbo.Funcionarios.nome, DATEPART(hour, Falta) AS faltas, DATEPART(hour, Coluna2) AS horasextra from dbo.Alteracoes inner join dbo.Funcionarios on dbo.Alteracoes.IDFuncionario = dbo.Funcionarios.IDFuncionario inner join dbo.Departamentos on dbo.Funcionarios.IDDepartamento = dbo.Departamentos.IDDepartamento WHERE Data = '" + dateTimePicker1.Value.ToString("yyyy/MM/dd") + "'", conn);
DataSet dt = new DataSet();
SDA.Fill(dt, "dbo.Alteracoes.Data");
dataGridView1.DataSource = dt.Tables["dbo.Alteracoes.Data"];
conn.Close();
}
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
}
This code search for the data from the date i choose.
And now i just want cheack if the date selected is < from (select u_recpica from e_industrial.dbo.e1) this table. If true show the data, if not is not valid
推荐答案
请参阅DateTime.Compare
文件
- DateTime.Compare方法(日期时间,日期时间)(系统) [ ^ ]
用法如下,你的情况:
SeeDateTime.Compare
documentation
- DateTime.Compare Method (DateTime, DateTime) (System)[^]
Usage is as follows, in your case:
if (DateTime.Compare(date1, date2) < 0)
{
//show data
}
else
{
//not valid
}
这篇关于如何检查我从日期时间选择器中选择的日期是否大于我的SQL数据库中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文