954,557 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to sort list of datarow?

i have a list of datarows. each row is having mutiple columns like userid,date,flag,etc.

i want to sort the based on date. how can i do that ?

Dim

listOfRows As New List(Of DataRow)()

 

For value As Integer = c To 
count - 1 

r = tableToRead.Rows(value)

listOfRows.Add(r)

i want to sort the listOfRows in ascending order of date which is a column in a row

abc88
Newbie Poster
10 posts since Jul 2011
Reputation Points: 10
Solved Threads: 0
 

If tabletoread is a datatable, then sort before getting the records

adam_k
Practically a Posting Shark
803 posts since Jun 2011
Reputation Points: 256
Solved Threads: 149
 
If tabletoread is a datatable, then sort before getting the records

yeah adam_k is right, for addition you can use SQL Order By
statement, for example:

this one sort your data by date in ascending order
SELECT * FROM [table_name]ORDER BY [Date]

this one sort your data by date in ascending order
SELECT * FROM [table_name] ORDER BY [Date] DESC

aldeene
Junior Poster in Training
70 posts since Jul 2011
Reputation Points: 10
Solved Threads: 3
 

You can use Sort method of list.

....
     listOfRows.Sort(AddressOf Comp)
...
End Sub

'Sort on 1st column
Shared Function Comp(ByVal v1 As DataRow, ByVal v2 As DataRow) As Integer
        If v1(0) > v2(0) Then
            Return 1
        Else
            If v1(0) < v2(0) Then
                Return -1
            Else
                Return 0
            End If
        End If
End Function
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You