To Check if Two DataTables are Same or not

Nadeemshaik
Posted by Nadeemshaik under C# category on | Points: 40 | Views : 873
 public bool IsDatatableSame(DataTable tbl1, DataTable tbl2)
{
int tbl1_Count = 0;
int tbl2_Count = 0;
for (int i = 0; i <= tbl1.Rows.Count - 1; i++)
{
if (!string.IsNullOrEmpty(tbl1.Rows[i][4].ToString()))
{
tbl1_Count = tbl1_Count + 1;
}
}
for (int i = 0; i <= tbl2.Rows.Count - 1; i++)
{
if (!string.IsNullOrEmpty(tbl2.Rows[i][4].ToString()))
{
tbl2_Count = tbl2_Count + 1;
}
}
if (tbl1_Count != tbl2_Count || tbl1.Columns.Count != tbl2.Columns.Count)
return false;

return true;
}

Comments or Responses

Login to post response