// Function Description: Compares the similarities and differences between data tables in two access databases based on the ID field
// The first database of P1
// P2 second database
// Tname name of the data table to be compared
Function comprecordbyid (adoquery: tadoquery; P1, P2, tname: string): Boolean;
VaR
Sqlstr: string;
Begin
Sqlstr: = 'select * from ('+
'Select t1.id, t2.id from ['+ p1 +']. '+ tname + 'as T1 left join' + tname + 'as T2 on t1.id = t2.id' +
'Union '+
'Select t1.id, t2.id from ['+ p1 +']. '+ tname + 'as T1 right join' + tname + 'as T2 on t1.id = t2.id' +
')' +
'Where t1.id is null' + // records not found in the first database
'Or t2.id is null'; // records not found in the second database
Adoquery. close;
Adoquery. connectionstring: = 'provider = Microsoft. Jet. oledb.4.0; Data Source = '+ p2 +'; persist Security info = false ';
Adoquery. SQL. Text: = sqlstr;
Adoquery. open;
End;
The above function has a bug. Please refer to another article.Article
Http://blog.csdn.net/siow/archive/2008/05/29/2493944.aspx