Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
 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 
Posted
Updated 4-Jan-18 6:21am

1 solution

See DateTime.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
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900