ADO.NET: Copy Rows from DataTable to a new DataTable

Found one interesting thing in ADO.NET programming.

Wanted to copy some error free records from an existing table to a new table.

C# Code is:

(Assumes we have a table named tblExisting with some rows hasErrors is true)

DataTable tblErrorFree=new DataTabel();

foreach(DataRow r in tblExisting)
if(r.HasErrors)
tblErrorFree.ImportRow(r);

// Now the tblErrorFree datatable contains all the error free records of tblExisting datatable

Comments