开发者

DataView Does Not Filter Properly on TIMESTAMP

开发者 https://www.devze.com 2022-12-12 02:19 出处:网络
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 n

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);
            }

        }


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消