Click here to Skip to main content
15,886,797 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Datatable I want to compare the values and swap the rows
original table1
PName       CN   CR   DS
prog       2.4  2.8  1.5
diff       1.7  0.5  2.2
new        1.2  2.1  1.7
  
"CN< 1.6 AND DS >1.5" 
then that ROW has to be moved to top


output
PName      CN   CR    DS
new        1.2  2.1  1.7
prog        2.4  2.8  1.5
diff       1.7  0.5  2.2
Posted
Updated 28-Mar-14 3:53am
v11

DataTable has a sort interface:
C#
mydatatable.DefaultView.Sort = "pname asc";

http://stackoverflow.com/questions/5005658/how-do-you-sort-a-datatable-given-column-and-direction[^]

EDIT:
Try the following :
C#
DataRow[] rows1=mydatatable.Select("CN< 1.6 AND DS >1.5");
 
Share this answer
 
v2
Comments
FarhanShariff 28-Mar-14 9:41am    
I dont want to sort I want to swap Row to top based on condition "CN< 1.6 AND DS >1.5"
Mehdi Gholam 28-Mar-14 9:44am    
What you are showing you want is a sort!
FarhanShariff 28-Mar-14 9:47am    
check improved question
Mehdi Gholam 28-Mar-14 10:03am    
see the edit
XML
DataView dv = dt.DefaultView;
dv.RowFilter = "CN < 1.6 AND DS > 1.5";
DataTable dt2 = dv.ToTable();
dv.RowFilter = "NOT(CN < 1.6 AND DS > 1.5)";
DataTable dt3 = dv.ToTable();
dt2.Merge(dt3);
dt = dt2;
dv = null;
dt2 = dt3 = null;
 
Share this answer
 

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