User1535942433 posted
Hi bsurendiran,
1)These two DataTables has same number of columns
You could compare two datatable columns' count.Just like this:
if (dta.Columns.Count != dtb.Columns.Count)
{
ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('These datatable have different column number!');", true);
}
2)These two DataTables has same number of columns and it has same name?
You could check wheather one datatable column contains another datatable column name.Just like this:
for (int i = 0; i < dta.Columns.Count; i++)
{
if (!dtc.Columns.Contains(dta.Columns[i].ColumnName))
{
ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('These datatable have different column name!');", true);
}
}
3)These two DataTables has same number of columns and it has same name and it has same datatype?
You could compare two datatable column's datatype.Just like this:
for (int i = 0; i < dta.Columns.Count; i++)
{
for (int j = 0; j < dtd.Columns.Count; j++)
{
if (dta.Columns[i].DataType!=dtd.Columns[j].DataType)
{
ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('These datatable have different column datatype!');", true);
}
}
}
Best regards,
Yijing Sun