Sort dataset table

I have a dataset with one table the id is incremented, trying to sort a string field containing concatenated dateandtime - 20081113935.
Dim l_dv as dataview
l_dv = m_ds.Tables("Logs").defaultview
l_dv.sort = "DateAndSaveTime ASC"

This does not sort

Regads Neil
Who is Participating?
GesdevConnect With a Mentor Commented:
It's probably because the column is not a true datetime - you mention you have it as a concatenated string?  I might be wrong, but sorting strings is completely different to sorting dates.  I'd recommend casting your datetime in your query and then try sorting again - there shouldn't be any need to recreate another dataview.
Christopher KileCommented:
I would suggest creating a new DataView and sort that, then use the new DataView.  Sorting a DataTable within a DataSet just doesn't work, at least in my experience (if someone can prove me wrong, I'd be delighted to see how, would be a neat trick).
Dim l_dv as dataview
l_dv = New DataView(m_ds.Tables("Logs"))
l_dv.sort = "DateAndSaveTime ASC"

Open in new window

nenwmnAuthor Commented:
Gesdev the data comes from an xml log can I sort on the concatenated string.
Christopher KileConnect With a Mentor Commented:
I stand corrected :)
Yes, you can sort on the concatenated string.  Any numeric, string, or datetime field should sort, though it sometimes is difficult to recognize that it is, in fact, sorted depending on the data involved.  Also, you need to make sure you are binding to the .DefaultView rather than to the table itself (once you've set the .Sort).
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.