Compare only some colums : How to specify?

srikmrsrikmr Posts: 16
edited April 24, 2007 11:12PM in SQL Toolkit Previous Versions
Hi,
I am using SqlDataCompare in my code to compare my data.
Below are my 2 queries.
Query1:
I need to specify the columns which needs to be compared. How can i do this?
Below is my code which compares all the columns of the tables. But i need to specify and control the columns to be compared.

db1.RegisterForDataCompare(new ConnectionProperties(".", "DB1"));
db2.RegisterForDataCompare(new ConnectionProperties(".", "DB2"));

// Create the mappings between a certain table
TableMapping tableMapping = (TableMapping)mappings.Join(db1.Tables["[dbo].[Test]"], db2.Tables["[dbo].[Test]"]);

// Set the custom comparison key for the table
tableMapping.MatchingMappings.Clear();
tableMapping.MatchingMappings.Add(tableMapping.FieldMappings["Name"]);
tableMapping.RefreshMappingStatus();
// Set the where clause for the comparison
tableMapping.Where = new WhereClause("College = 'CollegeA' and Grade = 'A'");

// Peform the comparison
session.CompareDatabases(db1, db2, mappings);
TableDifference difference = session.TableDifferences["[dbo].[Test]"];

if (difference.DifferencesSummary.DifferenceCount() == 0)
Console.WriteLine("Both tables are Same");
else
Console.WriteLine("Difference of Tables exist.");

Query2:
What should i do if i want to specify different WHERE conditions for each of the database tables.
What i mean is, i need to have a WHERE condition which needs to be satisfied for Database1 and a second Where condition needs to be satisfied for Database2

Thanks in advance.

Comments

  • Brian DonahueBrian Donahue Posts: 6,590 New member
    Hi,

    No problem. Construct your WhereClause class with no arguments and use the WhereClause's Clause1 and Clause2 properties to set the where clause for db1 and db2:
    WhereClause w=new WhereClause();
    w.Clause1="College='CollegeA'";
    w.Clause2="Grade='A'";
    tableMapping.Where=w;
    

    P.S. -- I've moved this topic to the SQL Toolkit forum. :-)
  • Thank you Brian for your prompt response on my Query2,
    Your inputs for my Query1 also would of of great help.
    Regards
    SriKmr
Sign In or Register to comment.