Atualizar banco com novos registros

19/09/2014

0

Olá pessoal,

Estou com uma dúvida: Tenho dois bancos, um sqlite e um mysql, o que quero fazer é que para cada registro lido, ele verifique se o campo cnpj existe no mysql, isso quando estiver exportando pela segunda vez novos registros. Caso não tenha ele insira. Consegui bolar a lógica mas como tô perdido em como implementar no código. Segue o mesmo para tentarem me ajudar:

procedure TForm1.btnExportarDadosClick(Sender: TObject);
begin
  SqliteQuery.Close;
  SqliteQuery.Open;
  SqliteQuery.first;
  while not SqliteQuery.Eof do
  begin
    if MysqlQueryCNPJ.Value <> 0 then
      begin
      try
        MysqlQuery.Insert;
        MysqlQueryCNPJ.value := SqliteQueryCNPJ.value;
        MysqlQueryNOME.value := SqliteQueryNOME.value;
        MysqlQueryENDERECO.value := SqliteQueryENDERECO.value;
        MysqlQueryTELEFONE.value := SqliteQueryTELEFONE.value;
        MysqlQuery.Post;
      except
        on E: Exception do
        begin
          showmessage (E.message);
          if MysqlQuery.State = dsinsert then
            MysqlQuery.Cancel;
          break;
        end;
      end;
    SqliteQuery.edit;
    SqliteQueryEXPORT.Value := 'S';
    SqliteQuery.post;
    SqliteQuery.next;
      end;
  end;
end;
Yuri Neves

Yuri Neves

Responder

APRENDA A PROGRAMAR DO ZERO AO PROFISSIONAL

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar