Results 1 to 8 of 8

Thread: Alle records in tabel weggooien ?

  1. #1

    Question Alle records in tabel weggooien ?

    Hoi,

    in mijn delphi 5 programma gebruik enkele tabellen, die ik vanuit een ander programma vul met import-bestanden (ascii, csv). Nu wil ik iedere keer als ik begin met importeren, de complete tabel leeggooien. De tabelstructuur moet natuurlijk bewaard worden. Hoe doe ik dit het eenvoudigst ?

    Ik werk trouwens met een BDE-koppeling naar een MS Access database.

    gr.
    Hans

  2. #2
    5th member of nldelphi
    Join Date
    Mar 2001
    Location
    Alkmaar
    Posts
    2,127
    Hans,

    Mischien dat je aan het onderstaande wat hebt.

    Code:
    procedure TForm.BtLeegTabelClick(Sender: TObject);
    begin
      if not DM.Tabel.IsEmpty then
        begin
          if MessageDlg('Weet u zeker dat u de tabel wilt legen ?', mtConfirmation, [mbYes, mbNo], 0) = mrYes then
            begin
              DM.Tabel.Cancel; //haald tabel uit insert, edit
              DM.Tabel.Exclusive := True; //zet tabel in exclusive mode.
              DM.Tabel.EmptyTable; //Leeg tabel, waarna deze autom. wordt geslot.
              DM.Tabel.Exclusive := False; 
              DM.Tabel.Open; //Heropen tabel.
              BtLeegTabel.Enabled := False;
              FormShow(nil);
            end;
        end;
    end;
    Succes,

    Richard
    RLD

  3. #3
    Of gebruik een SQL statement: delete from <TabelNaam>
    Marcel

  4. #4
    Ik heb het inderdaad gedaan met een SQL statement 'delete from tabel'.
    Dit werkt perfect !

    Bedankt,
    Hans

  5. #5
    Doe liever TRUNCATE als je toch SQL gebruikt:
    TRUNCATE TABLE differs from DELETE FROM ... in the following ways:

    Truncate operations drop and re-create the table, which is much faster than deleting rows one by one.
    Not transaction-safe; you will get an error if you have an active transaction or an active table lock.
    Doesn't return the number of deleted rows.
    As long as the table definition file `table_name.frm' is valid, the table can be re-created this way, even if the data or index files have become corrupted.
    TRUNCATE is an Oracle SQL extension.

  6. #6
    TRUNCATE is an Oracle SQL extension.
    Werkt dat dan ook op een Access database?
    Marcel

  7. #7
    Senior Member
    Join Date
    Oct 2001
    Location
    Antwerpen
    Posts
    117
    Truncate werkt in ieder geval niet op mijn Access 2000, wel op SQL Server 2000
    Johan

  8. #8

    Thumbs up

    Gebruik doodgewoon een TADO Command component:

    gebruik bv deze code

    procedure Tdata.MaakTabelLeeg(strTabel:string);
    var
    str:string;
    begin
    str:='Delete * from {T}';
    str:=AnsiReplaceStr(str,'{T}',strTabel);
    ADOCommand1.CommandText:=str;
    ADOCommand1.Execute;
    end;

    Tabel is leeg. Werkt Altijd. Mis je natuurlijk ADO gebruikt.

    Harry Offermans

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Alle records uit Adotable kolom in memo laden
    By jeffvdven in forum Databases
    Replies: 14
    Last Post: 09-Dec-04, 10:25
  2. Replies: 8
    Last Post: 08-Apr-04, 17:33
  3. Dubbele records verwijderen uit firebird tabel
    By r.nijenhuis in forum Databases
    Replies: 12
    Last Post: 25-Aug-03, 17:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •