Compare only some colums : How to specify?
srikmr
Posts: 16
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.
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
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:
P.S. -- I've moved this topic to the SQL Toolkit forum. :-)
Your inputs for my Query1 also would of of great help.
Regards
SriKmr