views:

31

answers:

1

I built a dialog so that when the user decides to print the DataGridView, he can select the date range for which to print. This works fine; however, either I am missing something or the filtering is not working properly. In order to filter by a range and for it to include the correct days, you have to select one day prior to the actual date you want to filter. It is like the filter is not inclusive. The dates are returned from two DateTimePickers and passed as a string to my function. The following is my code:

private void CreateFilteredDataGridView(DataGridView dgv, string fromDate, string toDate)
        {
            try
            {
                myDataSet = new DataSet();
                myDataSet.CaseSensitive = true;

                DataAdapter.SelectCommand.Connection = myConnection;
                DataAdapter.TableMappings.Clear();
                DataAdapter.TableMappings.Add("Table", "INVENTORY");
                DataAdapter.Fill(myDataSet);

                myDataView = new DataView(myDataSet.Tables["INVENTORY"], "TIMESTAMP >= '" + Convert.ToDateTime(fromDate) + "' AND TIMESTAMP <= '" + Convert.ToDateTime(toDate) + "'", "TIMESTAMP", DataViewRowState.CurrentRows);
                dgv.DataSource = myDataView;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

        }
A: 

Don't know if this is an issue but what about the time part? How does the comparison evaluate when you don't set the time explicitly? (Doesn't look like you're caring about the time of day in your table.)

John at CashCommons
Has no effect when I don't specify it in other cases
0A0D