locked
using datagridview to show only a certain date RRS feed

  • Question

  •  

    hi,
    I tried to use sql to get only those rows where the date column is on a selected month (from 1-12). I tried the 'like' keyword and using the MONTH(date) TSQL function which does not work here.
    Do you know how to get only these rows , using a view? or do I have to go through all rows and check the date and than build a new table with what i have found?
    Saturday, May 31, 2008 9:11 AM

Answers

  • You can filter the dates as something like this

    Code Snippet

    private void Form6_Load(object sender, EventArgs e)

            {

                DataTable dt = new DataTable();

                dt.Columns.Add("date",typeof(DateTime));

                dt.Rows.Add("2008/01/02");

                dt.Rows.Add("2008/02/02");

                dt.Rows.Add("2008/03/02");

                dt.Rows.Add("2008/04/02");

                dt.Rows.Add("2008/05/02");

                dt.Rows.Add("2008/06/02");

     

                dt.DefaultView.RowFilter = "date > #2008/02/01# and date < #2008/04/03#";

     

                this.dataGridView1.DataSource = dt;

            }

     

     



    Tuesday, June 3, 2008 9:39 AM