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

Recommended Answers

All 3 Replies

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

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

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
commented: agree +13
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.