Israel

Israel

  • 697
  • 1.3k
  • 219.9k

two dates to found in with the name "x"

Dec 22 2014 6:44 PM
Hi!

I would like to make filter between two dates and name  (for instance, show me between 20/12/2014 to 24/12/2014 where the name Sham is found) :

conn.Open();
            OleDbCommand cmd = conn.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "select * from company where data between ? and ?";
            var param1 = new OleDbParameter("@StartDate", OleDbType.Date);
            var param2 = new OleDbParameter("@EndDate", OleDbType.Date);

            param1.Value = dataStart.Value.Date;
            param2.Value = dataEnd.Value.Date;

            if (dataStart.Value <= dataEnd.Value)
            {
                cmd.Parameters.Add(param1);
                cmd.Parameters.Add(param2);
            }
            else
            {
                cmd.Parameters.Add(param2);
                cmd.Parameters.Add(param1);
            }

            cmd.ExecuteNonQuery();
            DataTable dt = new DataTable();
            OleDbDataAdapter da = new OleDbDataAdapter(cmd);
            da.Fill(dt);
            conn.Close();
            dataGridView1.DataSource = dt;
        }


Answers (2)