2015年2月25日 星期三

檢查兩個DataTable是否相同


   1: public static bool AreTablesTheSame(DataTable tbl1, DataTable tbl2)
   2: {
   3:     if (tbl1.Rows.Count != tbl2.Rows.Count || tbl1.Columns.Count != tbl2.Columns.Count)
   4:         return false;
   5:  
   6:  
   7:     for (int i = 0; i < tbl1.Rows.Count; i++)
   8:     {
   9:         for (int c = 0; c < tbl1.Columns.Count; c++)
  10:         {
  11:             if (!Equals(tbl1.Rows[i][c], tbl2.Rows[i][c]))
  12:                 return false;
  13:         }
  14:     }
  15:     return true;
  16: }
原作已忘記是誰

沒有留言:

張貼留言