Laço de repetição para ler tabela por completo
Gostaria de saber como fazer um laço de repetição para que uma determinada tabela leia todos os seus arquivos e grave em outra tabela. Tipo assim:
while TbClientesParadox.eof do begin
QueryClientesFire.Append;
QueryClientesFire.Fieldbyname('C_CODCLI').AsInteger := TbClientesParadoxC_CODCLI.AsInteger;
QueryClientesFire.FieldByName('C_NOME_RAZAO').AsString := TbClientesParadoxC_NOMECLI.AsString;
QueryClientesFire.FieldByName('C_TIPOPESSOA').AsString := 'F';
QueryClientesFire.Fieldbyname('C_CODEMP').AsInteger := 1;
QueryClientesFire.FieldByName('C_CODGRCLI').AsInteger := TbClientesParadoxC_TIPOCLI.AsInteger;
QueryClientesFire.Post; end; Mas não tenho certeza se irá ler todos os dados da TbClientesParadox e gravar na QueryClientesFire! Se alguém poder ajudar, agradeço!
QueryClientesFire.Append;
QueryClientesFire.Fieldbyname('C_CODCLI').AsInteger := TbClientesParadoxC_CODCLI.AsInteger;
QueryClientesFire.FieldByName('C_NOME_RAZAO').AsString := TbClientesParadoxC_NOMECLI.AsString;
QueryClientesFire.FieldByName('C_TIPOPESSOA').AsString := 'F';
QueryClientesFire.Fieldbyname('C_CODEMP').AsInteger := 1;
QueryClientesFire.FieldByName('C_CODGRCLI').AsInteger := TbClientesParadoxC_TIPOCLI.AsInteger;
QueryClientesFire.Post; end; Mas não tenho certeza se irá ler todos os dados da TbClientesParadox e gravar na QueryClientesFire! Se alguém poder ajudar, agradeço!
Thiago Santana
Curtidas 0
Respostas
Wilson Junior
01/02/2010
TbClientesParadox.First; { Para posicionar no primeiro registro }
while TbClientesParadox.Eof do
begin
QueryClientesFire.Append;
QueryClientesFire.Fieldbyname('C_CODCLI').AsInteger := TbClientesParadoxC_CODCLI.AsInteger;
QueryClientesFire.FieldByName('C_NOME_RAZAO').AsString := TbClientesParadoxC_NOMECLI.AsString;
QueryClientesFire.FieldByName('C_TIPOPESSOA').AsString := 'F';
QueryClientesFire.Fieldbyname('C_CODEMP').AsInteger := 1;
QueryClientesFire.FieldByName('C_CODGRCLI').AsInteger := TbClientesParadoxC_TIPOCLI.AsInteger;
QueryClientesFire.Post;
TbClientesParadox.Next; { Para ler o próximo registro }
end;
O seu componente "QueryClientesFire" deve ser do tipo TClientDataSet, para após fazer
QueryClientesFire.ApplyUpdates( 0 );
Espero ter ajudado.
GOSTEI 0
Alison Bissoli
01/02/2010
Nosso amigo deixou escapar, no lugar de
"while TbClientesParadox.Eof do" faça "while not TbClientesParadox.Eof do"
aí estará testando se não é o fim da tabela.
http://garotodesktop.blogspot.com
GOSTEI 0
Wilson Junior
01/02/2010
Bem lembrado, esqueci porque copiei do código do post anterior. Desculpem pelo erro.
GOSTEI 0
Douglas
01/02/2010
Amigos estou com pipino....tentei pegar este post de voces ai e tentei montar na minha imprenssão
mas nao deu
esta assim minha estrutura:
IBNFS_INNER1.Close;
IBNFS_INNER1.SQL.Clear;
IBNFS_INNER1.SQL.Add(select distinct produto.cod_produto,produto.descricao, produto.valor_tabela_1,);
IBNFS_INNER1.SQL.Add(nf_saida_itens.cod_produto, nf_saida_itens.nota_fiscal FROM produto );
IBNFS_INNER1.SQL.Add(LEFT JOIN nf_saida_itens ON produto.cod_produto = nf_saida_itens.cod_produto);
IBNFS_INNER1.SQL.Add(GROUP BY PRODUTO.cod_produto,PRODUTO.descricao,);
IBNFS_INNER1.SQL.Add(PRODUTO.valor_tabela_1,nf_saida_itens.nota_fiscal,nf_saida_itens.cod_produto);
IBNFS_INNER1.Prepare;
IBNFS_INNER1.Open;
//// {
IBNFS_INNER1.First;
while not IBNFS_INNER1.Eof do
begin
RLLabel55.Caption := IBNFS_INNER1.FieldValues[COD_PRODUTO];
IBNFS_INNER1.Next;
End;
mas nao deu
esta assim minha estrutura:
IBNFS_INNER1.Close;
IBNFS_INNER1.SQL.Clear;
IBNFS_INNER1.SQL.Add(select distinct produto.cod_produto,produto.descricao, produto.valor_tabela_1,);
IBNFS_INNER1.SQL.Add(nf_saida_itens.cod_produto, nf_saida_itens.nota_fiscal FROM produto );
IBNFS_INNER1.SQL.Add(LEFT JOIN nf_saida_itens ON produto.cod_produto = nf_saida_itens.cod_produto);
IBNFS_INNER1.SQL.Add(GROUP BY PRODUTO.cod_produto,PRODUTO.descricao,);
IBNFS_INNER1.SQL.Add(PRODUTO.valor_tabela_1,nf_saida_itens.nota_fiscal,nf_saida_itens.cod_produto);
IBNFS_INNER1.Prepare;
IBNFS_INNER1.Open;
//// {
IBNFS_INNER1.First;
while not IBNFS_INNER1.Eof do
begin
RLLabel55.Caption := IBNFS_INNER1.FieldValues[COD_PRODUTO];
IBNFS_INNER1.Next;
End;
GOSTEI 0