c# - Clean a DataTable in a loop moving used items to two other DataTables -
this question exact duplicate of:
i have main datatable
called dtmain
, 2 child datatables dtsuccess
, dtfail
. in while loop has 10 second delay in each iteration items in dtmain
added dtsuccess
, dtfail
. in each iteration dtmain
clean in other 2 lists.
i put code have tried here unfortunately not work.
while (dtmain.rows.count > 0) { var query = dt.asenumerable().except(dtsuccess.asenumerable(), datarowcomparer.default) .asenumerable().except(dtfail.asenumerable(), datarowcomparer.default); if (dtmain.asenumerable().any()) dtmain = query.copytodatatable(); thread.sleep(10000); }
i have received exceptions such as:
collection modified; enumeration operation might not execute
and invalidoperationexception
the source contains no datarows
try looping on variable (this solve collection modified problem) :
int = dtmain.rows.count ; while ( > 0) { var query = dt.asenumerable().except(dtsuccess.asenumerable(), datarowcomparer.default) .asenumerable().except(dtfail.asenumerable(), datarowcomparer.default); if (dtmain.asenumerable().any()) dtmain = query.copytodatatable(); thread.sleep(10000); = dtmain.rows.count ; }
Comments
Post a Comment