#region Compare whether the contents of two DataTables are equal. First, compare the quantity. If the quantity is equal, compare the contents.
/// <summary>
/// Compare whether the contents of two DataTables are equal. First, compare the quantity. If the quantity is equal, compare the contents.
/// </ summary>
/// <param name = "dtA"> </ param>
/// <param name = "dtB"> </ param>
public static bool CompareDataTable (DataTable dtA, DataTable dtB)
{
if (dtA.Rows.Count == dtB.Rows.Count)
{
if (CompareColumn (dtA.Columns, dtB.Columns))
{
// than content
for (int i = 0; i <dtA.Rows.Count; i ++)
{
for (int j = 0; j <dtA.Columns.Count; j ++)
{
if (! dtA.Rows [i] [j] .Equals (dtB.Rows [i] [j]))
{
return false;
}
}
}
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
/// <summary>
/// compare whether the two field collections have the same data type
/// </ summary>
/// <param name = "dcA"> </ param>
/// <param name = "dcB"> </ param>
/// <returns> </ returns>
private static bool CompareColumn (System.Data.DataColumnCollection dcA, System.Data.DataColumnCollection dcB)
{
if (dcA.Count == dcB.Count)
{
foreach (DataColumn dc in dcA)
{
// Find the same field name
if (dcB.IndexOf (dc.ColumnName)> -1)
{
// Test data type
if (dc.DataType! = dcB [dcB.IndexOf (dc.ColumnName)]. DataType)
{
return false;
}
}
else
{
return false;
}
}
return true;
}
else
{
return false;
}
}
#endregion
The above is the comparison of two DataTable content is equal, first than the quantity, the quantity is equal to the content content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!