Arsip: bagaimana men-delete semua record pada sebuah field?

 
user image
more 15 years ago

gormet

Salam, to the point aja, nama tabel = table1 fieldname = nomorUrut, tipe = integer saya telah coba men-delete semua record pada tabel1 dengan cara: 1. delete

begin
  table1.delete;
end;
hasilnya record (terlihat pada DBGrid) ter-delete nya cuman satu satu, ga langsung ter-delete semuanya. 2. destroy

begin
  table1.destroy;
end;
hasilnya record (terlihat pada DBGrid) ter-delete semua. namun ketika program di-close dan di-run kembali, record yang awalnya kelihatan tiada(pada DBGrid) muncul kembali (tidak ter-delete). pertanyaan saya: bagaimana men-delete semua record pada field: nomorUrut, tabel1? thx b 4 :)
user image
more 15 years ago

_lmz

@gormet: Salam, to the point aja, nama tabel = table1 fieldname = nomorUrut, tipe = integer pertanyaan saya: bagaimana men-delete semua record pada field: nomorUrut, tabel1? thx b 4 :)
Maksudnya apa mendelete semua record tapi "pada sebuah field"? Apa bedanya dengan hanya "mendelete semua record"? misal contohnya: table1: nomorUrut nama 1 a 2 b 3 c 1. mendelete semua record: hasilnya: table1: nomorUrut nama (kosong, tidak ada baris dalam tabel) kalau anda pakai SQL mungkin bisa dengan delete tanpa where. (DELETE FROM table1). kalau tidak mungkin: table1.first; while table1.recordcount > 0 do table1.delete; (dilakukan delete per record sampai kosong). method destroy itu cuma menghapus objek table di memory, bukan isi data dalam table itu sendiri. 2. mendelete field tersebut: hasilnya: table1: nama a b c kalau SQL mungkin ALTER TABLE DROP COLUMN. kalau selain itu gak tahu deh :) mungkin yang lainnya bisa menjawab.
user image
more 15 years ago

muktaf

update tabel.nama set nama=''; <--- nanti field nama jadi kosong ... begitu bukan maksudnya
user image
more 15 years ago

ags606

bingung maksudnya,,,, kl mau hapus 1 record coba perintah (delete from table1 where nomorUrut ="yang loe mau hapus") kl mau hapus semua record (delete from table1) --> seperti penjelasan Imz diatas moga membantu
user image
more 15 years ago

gormet

makasih atas jawabannya mas lmz, mas muktaf, dan mas ags606 :)
lmz wrote: Maksudnya apa mendelete semua record tapi "pada sebuah field"? Apa bedanya dengan hanya "mendelete semua record"?
mendelete semua record tapi "pada sebuah field". karena pada table1 hanya terdapat sebuah field(noUrut), jadi ga berbeda.
ags606 wrote: bingung maksudnya,,,,
maaf bila bikin bingung.. maksud nya bgini: saya punya tabel=table1, dengan sebuah field=noUrut. table1: noUrut 1 2 3 4 pengennya semua record pada field noUrut dihapus semua menjadi: table1: noUrut (kosong, tidak ada record)
lmz wrote: misal contohnya: table1: nomorUrut nama 1 a 2 b 3 c 1. mendelete semua record: hasilnya: table1: nomorUrut nama (kosong, tidak ada baris dalam tabel) kalau anda pakai SQL mungkin bisa dengan delete tanpa where. (DELETE FROM table1). kalau tidak mungkin: table1.first; while table1.recordcount > 0 do table1.delete; (dilakukan delete per record sampai kosong).
saya pake cara mas lmz yang ini (dan BERHASIL / SUKSES), seperti:

procedure TForm1.btn_clearClick(Sender: TObject);
begin
   table1.First;
   while table1.RecordCount>0 do
   table1.delete;
end;
lmz wrote: method destroy itu cuma menghapus objek table di memory, bukan isi data dalam table itu sendiri.
maklum, saya coba-coba aja, hehehe... makasih infonya, jadi nambah pengetahuan nih... :)
lmz wrote: 2. mendelete field tersebut: hasilnya: table1: nama a b c kalau SQL mungkin ALTER TABLE DROP COLUMN. kalau selain itu gak tahu deh mungkin yang lainnya bisa menjawab.
saya blum ngerti klo pake SQL, blum dipelajarir. ntar blajar ah.... klo pake cara yang ini nama field-nya(noUrut) ikut hilang/terhapus?
muktaf wrote: update tabel.nama set nama=''; <--- nanti field nama jadi kosong ... begitu bukan maksudnya
udah saya coba mas muktaf, namun error.

procedure TForm1.btn_clearClick(Sender: TObject);
begin
   update table1.noUrut set noUrut='';
end;
error yang muncul:
[Error] U_antrean.pas(74): Missing operator or semicolon [Error] U_antrean.pas(74): 'END' expected but 'SET' found [Fatal Error] P_antrean.dpr(5): Could not compile used unit 'U_antrean.pas'
ags606 wrote: kl mau hapus 1 record coba perintah (delete from table1 where nomorUrut ="yang loe mau hapus") kl mau hapus semua record (delete from table1) --> seperti penjelasan Imz diatas moga membantu
yang pertama error, klo yang kedua (dari mas lmz) berhasil. code yang pertama:

procedure TForm1.btn_clearClick(Sender: TObject);
begin
 delete from table1 where nomorUrut ="2"  
end;
error yang muncul:
[Error] U_antrean.pas(74): '(' expected but identifier 'from' found [Error] U_antrean.pas(74): Incompatible types [Error] U_antrean.pas(74): ':=' expected but '=' found [Fatal Error] P_antrean.dpr(5): Could not compile used unit 'U_antrean.pas'
makasih semua ....
user image
more 15 years ago

MrLee

ikut nimbrung ya; seharusnya jika menggunakan TTable; Khususnya paradox cukup dgn perintah Table1.EmptyTable; coba lihat aja di helpnya delphi; semoga berhasil
user image
more 15 years ago

gormet

MrLee wrote: kut nimbrung ya;
saya sangat senang dengan adanya respon dari rekan-rekan di delphi-id...
MrLee wrote: seharusnya jika menggunakan TTable; Khususnya paradox cukup dgn perintah Table1.EmptyTable; coba lihat aja di helpnya delphi; semoga berhasil
saya juga menggunakan paradox & TTable barusan saya coba

procedure TForm1.btn_hapusClick(Sender: TObject);
begin
   table1.EmptyTable;
{  table1.First;
   while table1.RecordCount>0 do
   table1.delete;
}
end;
namun hasil nya muncul error berupa message box, dengan isi error: "Project P_Loop.exe raised exception class EDBEngineError with message 'Table cannot be opened for exclusive use.'. Proses stopped. Use Step or Run to continue."
user image
more 15 years ago

MrLee

oh itu di TTable nya sebelum di open meemang harus di set propertiesnya Exclusive := True; sebab harus tidak di pakai oleh user lain; jadi

Table1.Exclusive := true;
Table1.open;
Table1.EmptyTable;
semoga bermanfaat
user image
more 15 years ago

gormet

oh itu di TTable nya sebelum di open meemang harus di set propertiesnya Exclusive := True; sebab harus tidak di pakai oleh user lain; jadi

   Table1.Exclusive := true; 
   Table1.open;
   Table1.EmptyTable; 
semoga bermanfaat
maaf nih MrLee, saya sudah coba namun masih gagal (muncul error).

procedure TForm1.btn_hapusClick(Sender: TObject);
begin
 Table1.Exclusive := true;
 Table1.open;
 Table1.EmptyTable;
 {  table1.First;
   while table1.RecordCount>0 do
   table1.delete;
}end;
hasil nya muncul error berupa message box, dengan isi error: "Project P_Loop.exe raised exception class EDBEngineError with message 'Table: cannot perform this operation on an open dataset'. Proses stopped. Use Step or Run to continue." Lalu saya coba cari di help, dengan mengetik: EmptyTable,example
dari help delphi (EmptyTable Example): The following example uses a table component to empty a database table. First the properties of the table component are set to specify the table that should be emptied. with Table1 do begin Active := False; DatabaseName := 'Delphi_Demos'; TableName := 'CustInfo'; TableType := ttParadox; EmptyTable; end;
contoh dari help delphi di atas saya coba:

procedure TForm1.btn_hapusClick(Sender: TObject);
begin
   with Table1 do
   begin
     Active := False;
     //DatabaseName := 'Delphi_Demos';
     TableName := 'D:\Antri boss !!\noUrut.db';
     TableType := ttParadox;
     EmptyTable;
   end;
 {  table1.First;
   while table1.RecordCount>0 do
   table1.delete;
}end;
namun hasil nya muncul error berupa message box, dengan isi error: "Project P_Loop.exe raised exception class EDBEngineError with message 'Table is busy. Table: D:\ANTRI BOSS !!\NOURUT.DB User: Rahmat. Proses stopped. Use Step or Run to continue.
user image
more 15 years ago

MrLee

oke deh kamu pertama bisa coba saat desain time; properties Table name isi 'D:\Antri boss !!\noUrut.db' . exclusive ganti true; . active jadi kan true; jika itu berhasil maka coding nya

  with Table1 do
  begin     
    Active := False;     
    TableName := 'D:\Antri boss !!\noUrut.db';  //boleh di buat lagi boleh tidak jika tdk brganti table
    Exclusice := True;
    EmptyTable;
  end;
semoga berhasil :D
more ...
  • Pages:
  • 1
  • 2
Share to

Random Topic

Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com