Click here to Skip to main content
16,014,677 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a datatabe with 4 columns part_No, Desc, Condiction and Qty, for each part number i have 2 row sales and returns.

Item1| Item Name1 | Purchase | 2
Item1| Item Name1 | returns | 1
Item2| Item Name2 | Purchase | 5
Item2| Item Name2 | returns | 1
Item3| Item Name3 | Purchase | 1
Item3| Item Name3 | returns | 0

i need to sort max purchase to up as below.

Item2| Item Name2 | Purchase | 5
Item2| Item Name2 | returns | 1
Item1| Item Name1 | Purchase | 2
Item1| Item Name1 | returns | 1
Item3| Item Name3 | Purchase | 1
Item3| Item Name3 | returns | 0

but when i sort not getting like this. please help me.

What I have tried:

Dim dv As New DataView(Temp_DataTable)
With dv

.Sort = "PN ASC, LS ASC"

End With
Posted
Updated 16-Feb-17 2:49am
Comments
Michael_Davies 16-Feb-17 7:06am    
Your column names do not match the .Sort list, guess PN is meant to be part_No but PN is not part_No if the column name is part_No, no idea what LS is as it does not even acronym any of your given column names.

Try .Sort = "part_No ASC, Qty DESC"
Karthik_Mahalingam 16-Feb-17 22:24pm    
.Sort = "PN ASC, LS ASC"
names doesn't make sense with the question.
kasunthilina 16-Feb-17 23:48pm    
Thank you very much. It worked. LS i menction as 'last summary' it was my datatable column name. but thank you again for you help.

sort the max sale data with descending order
You may try:

.Sort = "PN DESC, LS DESC"
 
Share this answer
 
Comments
kasunthilina 16-Feb-17 23:49pm    
thank you very much. it wordked.
Linq solution:

C#
var sortedtable = Temp_DataTable.AsEnumerable()
                  .OrderBy(x=>x.Field<string>("PN"))
                  .ThenByDescending(x=>x.Field<string>("LS"));


See:
Enumerable.OrderBy(TSource, TKey) Method (IEnumerable(TSource), Func(TSource, TKey)) (System.Linq)[^]
Enumerable.ThenByDescending(TSource, TKey) Method (IOrderedEnumerable(TSource), Func(TSource, TKey)) (System.Linq)[^]
 
Share this answer
 
Comments
kasunthilina 16-Feb-17 23:49pm    
thank you very much.
Maciej Los 17-Feb-17 3:21am    
You're very welcome.

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