Tell me how to compare two DataTable tables of the same type?
1 answer
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; }
- I would also check the input arguments to null, as in any decent
Compare
method. - andreycha - oneas correctly noted on SO tables must be pre-equally sorted. - Yura Ivanov
|