Sort dataset table

Posted on 2008-11-14
Last Modified: 2012-05-05
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
Question by:nenwmn
    LVL 23

    Expert Comment

    by:Christopher Kile
    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


    Accepted Solution

    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.
    LVL 2

    Author Comment

    Gesdev the data comes from an xml log can I sort on the concatenated string.
    LVL 23

    Assisted Solution

    by:Christopher Kile
    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).

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now