asp.net - How to remove more DataTable Columns using C#.Net? -


i have 1 datatable may have more columns. "netamount", "totalamount", "destination" datatable columns present in datatable.

here want remove 3 columns such "netamount", "totalamount" , "destination" datatable , take other column values in datatable.

i tried below , desired output.

  dtattribute.columns.remove("netamount"); //dtattribute main datatable   dtattribute.columns.remove("totalamount");   dtattribute.columns.remove("destination");   datatable dtitem = dtattribute.copy();       

but looks childish , lengthy. there other method do? please give suggestions.

there's nothing wrong code (except copying table after removing columns -- sure want?).

if want more abstract (instead of repeating same line again , again), might consider removing columns in loop:

var dtitem = dtattribute.copy();    // if want keep copy of original table  var toremove = new string[] {"netamount", "totalamount", "destination"}; foreach (col in toremove)     dtitem.columns.remove(col); 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -