public DataTable CompareTables(DataTable tbl1, DataTable tbl2)
{
DataTable dt3 = new DataTable();
for (int i = 0; i < tbl1.Columns.Count; i++)
{
dt3.Columns.Add(tbl1.Columns[i].ColumnName);
}
int found = 0;
for (int i = 0; i < tbl1.Rows.Count; i++)
{
found = 0;
for (int k = 0; k < tbl2.Rows.Count; k++)
{
if (Equals(tbl1.Rows[i][0], tbl2.Rows[k][0]))
{
found = 1;
DataRow dr = dt3.NewRow();
int hasValue = 0;
for (int c = 0; c < tbl1.Columns.Count; c++)
{
if (!Equals(tbl1.Rows[i][c], tbl2.Rows[k][c]))
{
dr[tbl2.Columns[c].ColumnName] = tbl2.Rows[k][c];
hasValue = 1;
}
}
if (hasValue == 1)
{
dt3.Rows.Add(dr);
hasValue = 0;
}
}
}
if (found == 0)
{
DataRow dr = dt3.NewRow();
for (int c = 0; c < tbl1.Columns.Count; c++)
{
dr[tbl2.Columns[c].ColumnName] = tbl1.Rows[i][c];
}
dt3.Rows.Add(dr);
}
}
return dt3;
}