How can I sort a datetime column in a dataset.

  • Thread starter Thread starter em00guy
  • Start date Start date
E

em00guy

Im using the following code to sort columns in a data set:
ds.Tables[0].DefaultView.Sort

However, datetime fields pulled from the database are sorted as strings
and thus incorrectly. How do I sort the datetime fields properly?
Thanks.
 
Hi,
Im using the following code to sort columns in a data set:
ds.Tables[0].DefaultView.Sort

However, datetime fields pulled from the database are sorted as strings
and thus incorrectly. How do I sort the datetime fields properly?
Thanks.

I did not check it, however it sounds strange to me that the datetime, which
is written in memory as a long that contains ticks which are counted by
hundereds of nanosecond units after the year 01:01:01 would be first
converted to a string. Straight sorting the tick gives the right result.

Did you try this?

(Assuming that your field is really a datetime field and not a real string).

I hope this helps,

Cor
 
It is a datetime field of the form, dd/mm/yyyy, in the sql server
source table. ADO.net loads all the fields into the dataset as strings.
I want ADO to load the SQL datetime field into the dataset as a .NET
DateTime type.
 
Is the DataColumn in your dataset a DateTime type?
Is column in Sql Server a DateTime type?
 
Hi,

If it is in the sql sever dd/mm/yyyy than it is a string in SQL server. The
datetime field is in SQL server as well in ticks however not in
hundred-nanosecond unit ticks however in milliseconds and than starting at
the day that the Georgian calendar started in the British Empire.

If the datetime is as a string in the SQL server than it is probably not
easy to use in a sort in a dataview.

I hope this helps,

Cor
 
Set the dataset's column in question to dateTime type.
BTW, what's your query like?
 
Im pulling from a stored procedure into a data set. My question is; how
do I set the column in .net? Thanks
 
NM, i figured it out. The issue was due to the stored procedure
converting the dattime values to varchars. Thanks for your help.
 
Back
Top