Ir para conteúdo
Fórum Script Brasil
  • 0

Apagar Conteudo De Uma Tabela


Guest Farina

Pergunta

Fiz um programa em delphi que irá gerar um arquivo txt que depois será lido em dataflex (classify), com o conteudo de uma tabela do access, até ai tudo certo, gerei o arquivo está tudo funcionando.

Mas eu gostaria de saber se tem um meio de eu apagar o conteudo da tabela, pois já terei gerado o arquivo de backup, para que ela não acabe ficando muito grande e diminua a performance do aplicativo.

desde já agradeço

Link para o comentário
Compartilhar em outros sites

5 respostass a esta questão

Posts Recomendados

  • 0

procedure TFrmGera.BitBtn1Click(Sender: TObject);

var

data1 : string;

data2 : string;

F: TextFile;

begin

//////////

Bitbtn1.Enabled := False;

messagedlg('CERTIFIQUE-SE QUE O DISQUETE ESTÁ INSERIDO NO DRIVE!',mtinformation,[mbok],0);

Data1:= (datetoStr(data_per1.Date));

Data2:= (datetoStr(data_per2.Date));

//////////////

Adotable1.Active := False;

AdoTable1.Active := True;

ADOtable1.Filtered:= false;

AdoTable1.Filter := 'Data_atend >=' +quotedstr(Data1)+' and data_atend <='+quotedstr(data2)+' and CONVENIO ='+quotedstr('1');

ADOtable1.Filtered:= true;

/////////////

AssignFile (F, 'A:\PLANCON.txt' );

Rewrite(f);

AdoTable1.First;

//GERAR CABECALHO

while not AdoTable1.EOF do

begin

//Tabela clinica

Write (f, AjustaStr ( adotable2.FieldByName ( 'NCOD_CLINICA' ).AsString, 10));

//Write (f, AjustaStr ( adotable2.FieldByName ( 'ANOM_CLINICA' ).AsString,15 ));

//

Write (f, AjustaStr ( adotable1.FieldByName ( 'GUIA_TIPO' ).AsString,15 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'ACOD_ASSOCIADO' ).AsString,30 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'NOME_ASSOCIADO').AsString,50 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'DATA_ATEND').AsString,8 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'HORA').AsString,5 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'ACID').AsString,8 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'NCRM').AsString,8 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'NSEQUENCIA').AsString,4 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'AESPECIAL').AsString,1 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'NESPEC').AsString,5 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'ATIPO').AsString,1 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'NVALOR').AsString,10 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'CONVENIO').AsString,5 ));

///TEXTO ESCRITO (POSIÇÕES/COLUNAS)

//cod_Clinica 1 a 10

//guia_tipo 11 a 25

//acod_associado 26 a 35

//nome_associado 36 a 85

//data_atend 86 a 93

//hora 94 a 98

//Acid 99 a 106

//NCRM 107 a 114

//nsequencia 115 a 118

//aespecial 119

//nespec 120 a 124

//atipo 125

//nvalor 126 a 135

//convenio 136 a 140

WriteLn ( f );

AdoTable1.Next;

end;

CloseFile ( f );

//FrmEmail.Show;

messagedlg('ARQUIVO GERADO COM SUCESSO!',mtinformation,[mbok],0);

FrmGera.Close;

////////////////////////

//If messagedlg('Arquivo Gerado e enviado para Santa Casa de Santos!!',mtinformation,[mbok],0) = mrok then

end;

Até ai está tudo funcionando OK, eu só queria aagora saber se tem como apagar o conteudo da tabela 1 (adoTable1)

Link para o comentário
Compartilhar em outros sites

  • 0

procedure TFrmGera.BitBtn1Click(Sender: TObject);

var

data1 : string;

data2 : string;

F: TextFile;

begin

//////////

Bitbtn1.Enabled := False;

messagedlg('CERTIFIQUE-SE QUE O DISQUETE ESTÁ INSERIDO NO DRIVE!',mtinformation,[mbok],0);

Data1:= (datetoStr(data_per1.Date));

Data2:= (datetoStr(data_per2.Date));

//////////////

Adotable1.Active := False;

AdoTable1.Active := True;

ADOtable1.Filtered:= false;

AdoTable1.Filter := 'Data_atend >=' +quotedstr(Data1)+' and data_atend <='+quotedstr(data2)+' and CONVENIO ='+quotedstr('1');

ADOtable1.Filtered:= true;

/////////////

AssignFile (F, 'A:\PLANCON.txt' );

Rewrite(f);

AdoTable1.First;

//GERAR CABECALHO

while not AdoTable1.EOF do

begin

//Tabela clinica

Write (f, AjustaStr ( adotable2.FieldByName ( 'NCOD_CLINICA' ).AsString, 10));

//Write (f, AjustaStr ( adotable2.FieldByName ( 'ANOM_CLINICA' ).AsString,15 ));

//

Write (f, AjustaStr ( adotable1.FieldByName ( 'GUIA_TIPO' ).AsString,15 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'ACOD_ASSOCIADO' ).AsString,30 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'NOME_ASSOCIADO').AsString,50 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'DATA_ATEND').AsString,8 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'HORA').AsString,5 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'ACID').AsString,8 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'NCRM').AsString,8 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'NSEQUENCIA').AsString,4 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'AESPECIAL').AsString,1 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'NESPEC').AsString,5 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'ATIPO').AsString,1 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'NVALOR').AsString,10 ));

Write (f, AjustaStr ( adotable1.FieldByName ( 'CONVENIO').AsString,5 ));

///TEXTO ESCRITO (POSIÇÕES/COLUNAS)

//cod_Clinica 1 a 10

//guia_tipo 11 a 25

//acod_associado 26 a 35

//nome_associado 36 a 85

//data_atend 86 a 93

//hora 94 a 98

//Acid 99 a 106

//NCRM 107 a 114

//nsequencia 115 a 118

//aespecial 119

//nespec 120 a 124

//atipo 125

//nvalor 126 a 135

//convenio 136 a 140

WriteLn ( f );

AdoTable1.Next;

end;

CloseFile ( f );

//FrmEmail.Show;

messagedlg('ARQUIVO GERADO COM SUCESSO!',mtinformation,[mbok],0);

FrmGera.Close;

////////////////////////

//If messagedlg('Arquivo Gerado e enviado !!',mtinformation,[mbok],0) = mrok then

end;

Até ai está tudo funcionando OK, eu só queria aagora saber se tem como apagar o conteudo da tabela 1 (adoTable1)

Link para o comentário
Compartilhar em outros sites

  • 0

A sua tabela deve ter um campo id, você poderia usar uma query dentro do while antes do -->> AdoTable1.Next, dessa forma:

Query1.Sql.Clear;
Query1.Sql.Add('Delete from tabela1');
Query1.Sql.Add('Where campo_id = '+''''+adotable2['campo_id']+''''+' ');
Query1.ExecSql;

acho que é isso, espero ter te ajudado. wink.gif

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...