开发者

Filtering DataGridView By Date Prior to Printing

I am filtering the DataGridView by a TIMESTAMP column so users can determine the date of data to print. Following is how I am creating my filtered DataGridView. However, in order to get the correct dates for instance Feb 8, 2010 to Feb 10, 2010, I have to select one date prior so the date range has to be Feb 7, 2010 to Feb 10, 2010 to get Feb 8, 2010 to Feb 10, 2010. This is too confusing for users.

TIMESTAMP is declared as SqlDbType.DateTime.

Where am I screwing up?

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

        DataAdapter.SelectCommand.Connection = myConnection;
        DataAdapter.TableMappings.Clear();开发者_Python百科
        DataAdapter.TableMappings.Add("Table", "GARAGE");
        DataAdapter.Fill(myDataSet);

        myDataView = new DataView(myDataSet.Tables["GARAGE"], "TIMESTAMP >= '" + 
        Convert.ToDateTime(fromDate) + "' AND TIMESTAMP <= '" + 
        Convert.ToDateTime(toDate) + "'", "TIMESTAMP", DataViewRowState.CurrentRows);

        dgv.DataSource = myDataView;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }

}


I can't tell what time you're passing in to that method, but it's possible that the time portion of your DateTime is causing the problem. Make sure that the from date starts at 00:00:00 (which it should already if no time is included) and that the end date contains 23:59:59.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜