0

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

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by __avd
0

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

Edited by aldeene: n/a

1

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
Votes + Comments
agree
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.