Maybe you know this, but as you speak of DataSets and tables in your question: DataSets are, simply put, a whole database in memory, with potentially multiple tables and possibly relations between those tables. To achieve what you're asking for, you only need two DataTables instead of DataSets.
I understand your question in that way, that you're only interested if the records of the two tables are identical or not, but not interested in the specific differences if there are any.
bool CompareInstalledToBaseline(OleDbConnection connection)
{
string query1 = "SELECT col1, col3 FROM InstalledConfigItem ORDER BY col1, col3;";
string query2 = "SELECT col1, col3 FROM BaselineConfigItem ORDER BY col1, col3;";
using (var installedDBAdapter = new OleDbDataAdapter(query1, connection))
using (var baselineDBAdapter = new OleDbDataAdapter(query2, connection))
using (var installedTable = new DataTable())
using (var baselineTable = new DataTable())
{
installedDBAdapter.Fill(installedTable);
baselineDBAdapter.Fill(baselineTable);
int[] columnsToCompare = new int[] { 0, 1 };
return CompareTables(installedTable, baselineTable, columnsToCompare);
}
}
bool CompareTables(DataTable table1, DataTable table2, IEnumerable<int> columnsToCompare)
{
if (table1.Rows.Count != table2.Rows.Count)
return false;
for (int rowIndex = 0; rowIndex < table1.Rows.Count; rowIndex++)
{
foreach (int colIndex in columnsToCompare)
{
if (!table1.Rows[rowIndex][colIndex].Equals(table2.Rows[rowIndex][colIndex]))
{
return false;
}
}
}
return true;
}
You could optimize this process by querying the record-count of both tables first. If that's already different, you won't have to load and compare the records any more.
If you have questions regarding the code please ask.