Results 1 to 4 of 4

Thread: [2.0] Order data table

  1. #1

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Question [2.0] Order data table

    Hi friends let me know how to order datatable
    Thanks

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Order data table

    No way to sort a DataTable is provided. If you need to sort the data in a DataTable then you normally do so via the DefaultView, which is a DataView. You set the Sort property, e.g. "Surname" or "Surname ASC" to sort in ascending order by surname or "DateOfBirth DESC" to sort in descending order by date of birth.

    To access the data in sorted order you then loop through the DefaultView instead of the Rows collection. Note that any controls bound to the DataTable get their data from the DefaultView already, so they will honour the sort order.

    If you absolutely must have a DataTable sorted a particular way then you should normally be doing that with your SQL code. If you can't for whatever reason then you can sort a DataView and then call its ToTable method, which will create a new DataTable with the same schema as the original and with the rows in the same order as the DataView.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Just Married shakti5385's Avatar
    Join Date
    Mar 2006
    Location
    Udaipur,Rajasthan(INDIA)
    Posts
    3,747

    Smile Re: [2.0] Order data table

    Can we sort data randomly? time by time
    When page refresh the it show different data on page

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Order data table

    Quote Originally Posted by shakti5385
    Can we sort data randomly? time by time
    When page refresh the it show different data on page
    Doesn't random kind of imply not sorted? You can't sort randomly. If you want a random order then you will have to select a random row one at a time until there are no rows left to select. The Unique Random Selections link in my signature can show you how to do that.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width