c# - adding datarows from array of datarows to top of datatable -
the array obtained linq query on datatable. when try add datatable gives exception row belongs table.
need add row top of table not @ bottom
datarow[] recovery_rows = sub_datatable.select("productid = " + last_product_id.tostring() + ""); //sub_datatable datatable (int rev_row = 0; rev_row < recovery_rows.count(); rev_row++) { datarow r_new = recovery_rows[rev_row]; // r_new = recovery_rows[rev_row]; dt_sub.rows.insertat(recovery_rows[rev_row], 0); }
you cannot add datarow
datatable
, has reference it's datatable
, throws exception if change table.
you can use datatable.importrow
imports row , adds end of datarowcollection
. next task move first position:
for (int rev_row = 0; rev_row < recovery_rows.length; rev_row++) { datarow r_new = recovery_rows[rev_row]; dt_sub.importrow(r_new); dt_sub.rows.removeat(dt_sub.rows.count - 1); dt_sub.rows.insertat(r_new, 0); }
Comments
Post a Comment