File Mentah Download
Bekaitan dengan artikel sebelumnya yang membahas tentang menghubungkan database menggunakan access di Delphi 7 kali ini saya akan melampirkan artikel yang berkaitan dengan Insert, Update, Delete. Nah, langsung saja saya terangkan.
Pertama-tama, Buka Delphi 7 nya lalu buat menunya seperti dibawah ini.
Lalu Hubungkan ADOConnention,ADOQuery,DataSource,dan DBGridmya seperti pada artikel Sebelumnya.
Untuk Tombol Tampilkkan Sudah dibahas diartikel sebelumnya.
Tambah
Untuk Tombol Tambah menggunakan Insert.
Klik icon bottom Tambah 2kali >> lalu tulis syntax nya seperti berikut.
with ADOQuery1 do
begin
Active:=False;
Close;
SQL.Clear;
SQL.Text:='insert into tb_barang values '+' ('+QuotedStr(Edit1.Text)+','+
''+QuotedStr(Edit2.Text)+','+
''+QuotedStr(Edit3.Text)+','+
''+DateToStr(DateTimePicker1.Date)+','+
''+QuotedStr(Edit5.Text)+','+
''+QuotedStr(Edit6.Text)+')';
ExecSQL;
end;
Application.MessageBox('Berhasil','Okey',0);
end;
Selanjutnya Pada icon bottom Ubah klik 2kali >> lalu tulis syntax nya seperti berikut.
begin
with ADOQuery1 do
begin
Active:=False;
Close;
SQL.Clear;
SQL.Text:='update tb_barang set nama_barang='+QuotedStr(Edit2.Text)+','+
'supplier='+QuotedStr(Edit3.Text)+','+
'tgl_beli='+DateToStr(DateTimePicker1.Date)+','+
'harga_beli='+QuotedStr(Edit5.Text)+','+
'harga_jual='+QuotedStr(Edit6.Text)+' where id_barang='+QuotedStr(Edit1.Text)+'';
ExecSQL;
end;
Application.MessageBox('Berhasil','Okey',0);
with ADOQuery1 do
begin
Active:=False;
Close;
SQL.Clear;
SQL.Text:='update tb_barang set nama_barang='+QuotedStr(Edit2.Text)+','+
'supplier='+QuotedStr(Edit3.Text)+','+
'tgl_beli='+DateToStr(DateTimePicker1.Date)+','+
'harga_beli='+QuotedStr(Edit5.Text)+','+
'harga_jual='+QuotedStr(Edit6.Text)+' where id_barang='+QuotedStr(Edit1.Text)+'';
ExecSQL;
end;
Application.MessageBox('Berhasil','Okey',0);
Selanjutnya klik icon bottom Hapus 2kali >> lalu tulis syntax nya seperti berikut.
begin
with ADOQuery1 do
begin
Active:=False;
Close;
SQL.Clear;
SQL.Text:='delete from tb_barang where id_barang='+QuotedStr(Edit1.Text)+'';
ExecSQL;
end;
Application.MessageBox('Berhasil','Okey',0);
with ADOQuery1 do
begin
Active:=False;
Close;
SQL.Clear;
SQL.Text:='delete from tb_barang where id_barang='+QuotedStr(Edit1.Text)+'';
ExecSQL;
end;
Application.MessageBox('Berhasil','Okey',0);
Dan Hasilnya seperti Dibawah ini. Semoga Bermanfaat... Mator Thank you.
0 komentar:
Post a Comment