Compare dates in DataView.RowFilter?

前端 未结 3 2014
广开言路
广开言路 2020-12-16 16:03

I am scratching my head over something rather stupid yet apparently difficult.

DataView dvFormula = dsFormula.Tables[0].DefaultView;
dvFormula.RowFilter = \"         


        
相关标签:
3条回答
  • 2020-12-16 16:40

    You need to wrap your dates with #, not apostrophes.

    dvFormula.RowFilter = "#" + startDate.ToString("MM/dd/yyyy") + "# < EndDate OR EndDate = #1/1/1900#"; 
    
    0 讨论(0)
  • 2020-12-16 16:51

    Depending on your data provider, you may need to escape dates with the # character rather than the ' character. In addition, I would format your dates in the format YYYY-MM-DD to ensure it can be recognized as a date correctly.

    0 讨论(0)
  • 2020-12-16 16:58

    This is the solution. Try this:

    filter = " (Date >= #" +
             Convert.ToDateTime(txtFromDate.Text).ToString("MM/dd/yyyy") +
             "# And Date <= #" +
             Convert.ToDateTime(txtToDate.Text).ToString("MM/dd/yyyy") +
             "# ) ";
    
    0 讨论(0)
提交回复
热议问题