Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am reading data from a CSV file and creating a DataSet from this input.
Each record added has an incremental "ID" starting from 1.
I need to sort the DataSet on "ID" Descending (i.e. reverse the order that the records were read in) but am failing dismally.

Included here is a basic summary of what I've tried.
When I step through and view the DataSet it has not Sorted.

Can anyone please advise what I am missing.

What I have tried:

Dim ds As New DataSet
Dim dt As DataTable = New DataTable()
Dim dr As DataRow

Dim IdCol As DataColumn = New DataColumn("ID", Type.GetType("System.Int32"))
Dim DtCol As DataColumn = New DataColumn("Date", Type.GetType("System.String"))
Dim AmCol As DataColumn = New DataColumn("Amount", Type.GetType("System.String"))
Dim BlCol As DataColumn = New DataColumn("Balance", Type.GetType("System.String"))
Dim DeCol As DataColumn = New DataColumn("Description", Type.GetType("System.String"))

dt.Columns.Add(IdCol)
dt.Columns.Add(DtCol)
dt.Columns.Add(AmCol)
dt.Columns.Add(BlCol)
dt.Columns.Add(DeCol)

dr = dt.NewRow()
dr("ID") = 1
dr("Date") = "22/04/2018"
dr("Amount") = "999.99"
dr("Balance") = "0.00"
dr("Description") = "B) Here is the transaction"
dt.Rows.Add(dr)

dr = dt.NewRow()
dr("ID") = 2
dr("Date") = "23/04/2018"
dr("Amount") = "888.89"
dr("Balance") = "1.00"
dr("Description") = "A) Here is the other transaction"
dt.Rows.Add(dr)

dt.DefaultView.Sort = "ID DESC"

ds.Tables.Add(dt)

ds.Tables("Table1").DefaultView.Sort = "ID DESC"
Posted
Updated 2-May-18 21:37pm

1 solution

 
Share this answer
 
Comments
Darrell de Wet 3-May-18 4:08am    
Got it. Thanks a lot Richard.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900