Tell me how to compare two DataTable tables of the same type?

    1 answer 1

    static bool AreTablesEqual(DataTable t1, DataTable t2) { if (t1.Rows.Count != t2.Rows.Count) return false; for (int i = 0; i < t1.Rows.Count; i++) { foreach(DataColumn col in t1.Columns) { if (!Equals(t1[i][col.Name], t2[i][col.Name])) return false; } } return true; } 

    Comparing DataTables

    • I would also check the input arguments to null, as in any decent Compare method. - andreycha
    • one
      as correctly noted on SO tables must be pre-equally sorted. - Yura Ivanov