There is very good blog at http://theonetechnologies.com/outsourcing/post/dataview-rowfilter-or-datatable-select-with-datetime-conditions.aspx
One needs to be very careful while using datetime in conditions for DataView.RowFilter or DataTable.Select. Because it is not that straight forward as comparing against string to numbers.
The string representation of datetime format depends upon your server/computer's culture or your application's thread culture. While the rowfilter or select method needs the datetime formatted as invariant or en-US culture.
Consider the scenario in which you are running your application running in Spanish culture, the following condition will fail in that case:
dataView.RowFilter = "Date = '" + dateVariable.ToString() + "'";
To overcome this kind of culture specific issues:
One needs to be very careful while using datetime in conditions for DataView.RowFilter or DataTable.Select. Because it is not that straight forward as comparing against string to numbers.
The string representation of datetime format depends upon your server/computer's culture or your application's thread culture. While the rowfilter or select method needs the datetime formatted as invariant or en-US culture.
Consider the scenario in which you are running your application running in Spanish culture, the following condition will fail in that case:
dataView.RowFilter = "Date = '" + dateVariable.ToString() + "'";
To overcome this kind of culture specific issues:
- Always use Date values enclosed within sharp characters # #
- Use culture invariant string as condition. For above mentioned example, the following will always work
I wanted to thank you for this excellent read!! I definitely loved every little bit of it.Cheers for the info!!!! & This is the perfect blog for anyone who wants to know about this topic. You know so much its almost hard to argue with you
ReplyDeleteweb development company india