c# - How to sort a datatable and then append rows at the bottom? -


i have function returning data table. function appends 1 row calculated sum. requirement has come sort data table. tried sort datatable append total row, data table taking total row in consideration. how can mitigate behaviour?

          dt.defaultview.sort = "totalearning desc"; //sorting first adding                 datarow dr = dt.newrow();                 dr.itemarray = new object[] { "total", dt.compute("sum(redeemed)", ""), dt.compute("sum(earning)", ""), dt.compute("sum(paidhousefee)", ""), dt.compute("sum(paidfine)", ""), dt.compute("sum(totalearning)", ""), dt.compute("sum(noofdayspresent)", ""), dt.compute("sum(noofdaysabsent)", ""), dt.compute("sum(avgdaily)", "") };                 dt.rows.insertat(dr, dt.rows.count); 

i suggest use linq-to-dataset instead more powerful , more readable:

dt = dt.asenumerable()      .orderby(row => row.field<string>(0) == "total")      .thenbydescending(row => row.field<int>("totalearning"))      .copytodatatable(); 

i have presumed totalearning int-column. correct accordingly.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -