Comparando o Banco para atualiza-lo

18/01/2013

1

Caros Amigos,
Pelo ADOQury1 pego dados de um DB1 , e o insiro no DB2. Oproblema é quando acrescento um cliente no DB1 não atualiza no DB2.

Me ajudem!!!
Segue o codigo


procedure TForm1.Button1Click(Sender: TObject);
begin

While Not ADOQuery1.Eof do
begin

Form1.SDQuery1.SQL.Clear;
if SDQuery1.SQL.Add('SELECT * FROM Cliente WHERE ListID <> '+quotedStr(ADOquery1.fieldByname('ListID').asString)+'')

begin
Form1.SDQuery1.SQL.Clear;
Form1.SDQuery1.SQL.Add('INSERT INTO Cliente (ListID, RazaoNome, CNPJ, NomeFantasia, Logradouro, Numero, Bairro, Municipio, IE) '+
' values ('+quotedStr(ADOquery1.fieldByname('ListID').asString)+','+quotedStr(ADOquery1.fieldByname('CompanyName').asString)+','+quotedStr(ADOquery1.fieldByname('CustomFieldCNPJ').asString)+','+quotedStr(ADOquery1.fieldByname('CompanyName').asString)+','+quotedStr(ADOquery1.fieldByname('BillAddressAddr1').asString)+','+quotedStr(ADOquery1.fieldByname('BillAddressAddr2').asString)+','+quotedStr(ADOquery1.fieldByname('BillAddressAddr3').asString)+','+quotedStr(ADOquery1.fieldByname('BillAddressAddr4').asString)+','+quotedStr(ADOquery1.fieldByname('CustomFieldInscEstadual').asString)+' )');
Form1.SDQuery1.Open;

end
else
begin

Form1.SDQuery1.SQL.Clear;
Form1.SDQuery1.SQL.Add('SELECT * FROM Cliente WHERE ListID = '+quotedStr(ADOquery1.fieldByname('ListID').asString)+'');
Form1.SDQuery1.Open;


SDQuery1.Active:=false;
Form1.SDQuery1.SQL.Add('UPDATE Cliente SET ListID='+quotedStr(ADOquery1.fieldByname('ListID').asString)+', RazaoNome='+quotedStr(ADOquery1.fieldByname('CompanyName').asString)+', CNPJ='+quotedStr(ADOquery1.fieldByname('CustomFieldCNPJ').asString)+', IE='+quotedStr(ADOquery1.fieldByname('CustomFieldInscEstadual').asString)+' WHERE ListID='+quotedStr(ADOquery1.fieldByname('ListID').asString)+'');
Form1.SDQuery1.ExecSQL;

end;
ADOQuery1.next;
end;

end;
Responder

Posts

18/01/2013

Bruno Leandro

ola francis qual banco de dados voce utiliza
Responder