贴一段自己写的代码,注意数据库的关键字冲突
procedure DisposeData(_ADOTem, _ADOdata: TADOQuery;
FileName: string);
var i, j, StartCol: integer;
begin
if _ADOTem.RecordCount < 1 then
Exit;
_ADOdata.Close;
//TMP11 为事先写好的SQL select 唯一标识 AS fNo, * from table
if Pos('TMP11', FileName) <> 0 then
_ADOData.SQL.Text := TMP11;
_ADOdata.Open;
_ADOTem.First;
if pos('AS', _ADOData.SQL.Text) <> 0 then
StartCol := 1
else
StartCol := 0;
while not _ADOTem.Eofdo
begin
if _ADOdata.Locate('fNo', _ADOTem.FieldByName('fNo').AsString, [])
then
_ADOdata.Edit
else
_ADOdata.Append;
try
for i := StartCol to _ADOTem.FieldCount - 1do
for J := StartCol to _ADOTem.FieldCount - 1do
if _ADOdata.Fields.FieldName = _ADOTem.Fields[j].FieldName then
if _ADOdata.Fields.Value = _ADOTem.Fields[j].Value then
break
else
begin
_ADOdata.Fields.Value := _ADOTem.Fields[j].Value;
break;
end;
_ADOdata.Post;
except
if debughook <> 0 then
application.MessageBox(pchar(_ADOData.SQL.Text), '错误提示', MB_OK);
//application.MessageBox(pchar(_ADOData.Fields.FieldName + '////' + _ADOTem.Fields[j].FieldName), '', MB_OK);
end;
_ADOTem.Next;
end;
_ADOData.Close;
_ADOTem.Close;
//删除成功后的XML
deletefile(ExtractFilePath(Application.ExeName) + 'data/' + FileName);
end;