Options

STK 3 - Programmatically choose the compared data columns

Brian DonahueBrian Donahue Posts: 6,590 Bronze 1
edited October 8, 2004 10:31AM in Knowledge Base
  • Date: 8 October 2004
  • Affected Versions: RedGate.SQLDataCompare.Engine.dll 3.x
In SQL Data Compare, you can choose the columns of a table in which you'd like to compare the data. The same is true of a Toolkit application. Rather than accepting the default as shown in the example application that is included in the SQL Toolkit, you create a list of your own columns to compare or exclude columns conditionally.

In the example application, find these lines of code:
//set up the table comparison setting
TableComparisonSettings settings=new TableComparisonSettings();
foreach (Table table in commonTables)
{
settings.Add(new TableComparisonSetting(table.FullyQualifiedName, table.Fields, table.PrimaryKey.Fields));
}
Add to this a new instance of RedGate.SQLDataCompare.Engine.Fields, then populate this object with the names of the columns that you want to compare using its' Add() method. Finally, pass in the Fields() that you had created to the SessionSettings as an argument to a new TableComparisonSetting.

Here is an example:
foreach (Table table in commonTables)
{
if (table.FullyQualifiedName=="foo") {
Fields fc = new Fields();
foreach (Field f in table.Fields)
{
if (f.Name!="bar") fc.Add(f);
}
settings.Add(new TableComparisonSetting(table.FullyQualifiedName, fc, table.PrimaryKey.Fields));
}
else settings.Add(new TableComparisonSetting(table.FullyQualifiedName, table.Fields, table.PrimaryKey.Fields));

}

In this example, the 'bar' column is excluded from the comparison of the table called 'foo'. In all other tables, all columns are compared. The logic can easily be reversed to include a collection of columns rather than exclude them.
Sign In or Register to comment.