0% found this document useful (0 votes)
15 views

Source Code Adoquery CRUD

Uploaded by

Fery
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Source Code Adoquery CRUD

Uploaded by

Fery
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Interface

procedure tampil();

procedure reload();

procedure btnprvClick(Sender: TObject);

procedure btnnextClick(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;
var

Form2: TForm2;

input : Tcomponent;

jk : String;

implementation

{$R *.dfm}

procedure TForm2.tampil;

begin

ednoktp.text := ADOQuery1['noktp'];

ednama.text := ADOQuery1['nama'];

ednohp.Text := ADOQuery1.FieldByName('nohp').Value;

Edalamat.Text := ADOQuery1.FieldByName('alamat').Value;

Edlahir.Text := ADOQuery1.FieldValues['asal'];

Edkerja.Text := ADOQuery1.FieldValues['pekerjaan'];

Edumur.Text := ADOQuery1['umur'];

if ADOQuery1['jeniskelamin'] = 'L' then

begin

rdblaki.Checked := True;

rdbperempuan.Checked := False;

end

else

begin

rdblaki.Checked := False;

rdbperempuan.Checked := True;

end;

end;
//procedure yang digunakan untuk memperbaharui isi tabel

procedure tform2.reload;

begin

adoquery1.SQL.Clear;

adoquery1.SQL.add('SELECT * FROM person');

adoquery1.active:=true;

end;

procedure TForm2.btnInputClick(Sender: TObject);

begin

for input in self do

begin

//Cek kotak isian

if (input is TEdit) and (TEdit(input).Text = '') then

begin

application.MessageBox('Harap isi semua inputan','Peringatan');

TEdit(input).SetFocus;

Exit;

end;

//cek radiobutton

if (not rdblaki.Checked) and (not rdbperempuan.Checked) then

begin

application.MessageBox('Jenis kelamin harus dipilih','Peringatan');

Exit;

end;

end;
//mencegah duplicate entry

if adoquery1.locate('noktp',ednoktp.text, [])= true then

begin

ShowMessage('Nomor KTP sudah terdaftar');

ednoktp.Clear; ednoktp.SetFocus;

end

else

begin

if rdblaki.Checked then jk := 'L' else jk :='P';

//cara eksekusi query INSERT INTO (Create) menggunakan parameters

adoquery1.SQL.text :='INSERT INTO person VALUES(:ktp, :nama, :jk, :nohp, :alamat, :lahir, :kerja,
:umur)';

adoquery1.Parameters.ParamByName('ktp').Value :=ednoktp.text;

adoquery1.Parameters.ParamByName('nama').Value :=ednama.text;

adoquery1.Parameters.ParamByName('jk').Value :=jk;

adoquery1.Parameters.ParamByName('nohp').Value :=ednohp.text;

adoquery1.Parameters.ParamByName('alamat').Value :=edalamat.text;

adoquery1.Parameters.ParamByName('lahir').Value :=edlahir.text;

adoquery1.Parameters.ParamByName('kerja').Value :=edkerja.text;

adoquery1.Parameters.ParamByName('umur').Value :=edumur.text;

adoquery1.ExecSQL;

reload();

end;

end;

procedure TForm2.btndeleteClick(Sender: TObject);

begin

//cek nik untuk dihapus

if adoquery1.locate('noktp',ednoktp.text, [])= false then


begin

ShowMessage('Nomor KTP tidak terdaftar');

ednoktp.Clear;

ednoktp.SetFocus;

end

else

begin

if Application.MessageBox('Yakin mau hapus data ini?', 'Konfirmasi Hapus', 4)= mrYes then

//eksekusi query DELETE menggunakan SQL.add

adoquery1.SQL.Clear;

adoquery1.SQL.add('DELETE FROM person WHERE noktp=' + quotedstr(ednoktp.text));

adoquery1.ExecSQL;

reload();

ShowMessage('Data berhasil dihapus');

end;

end;

procedure TForm2.btnEditClick(Sender: TObject);

begin

for input in self do

begin

//Cek kotak isian

if (input is TEdit) and (TEdit(input).Text = '') then

begin

application.MessageBox('Harap isi semua inputan','Peringatan');

TEdit(input).SetFocus;

Exit;

end;
//cek radiobutton

if (not rdblaki.Checked) and (not rdbperempuan.Checked) then

begin

application.MessageBox('Jenis kelamin harus dipilih','Peringatan');

Exit;

end;

end;

//cek nik untuk diedit

if adoquery1.locate('noktp',ednoktp.text, [])= false then

begin

ShowMessage('Nomor KTP tidak terdaftar');

ednoktp.Clear;

ednoktp.SetFocus;

end

else

begin

if rdblaki.Checked then jk := 'L' else jk :='P';

//cara eksekusi query menggunakan penggabungan string.

adoquery1.SQL.text :='UPDATE person SET nama=' + QuotedStr(ednama.Text) + ', jeniskelamin=' + QuotedStr(jk) +

', nohp=' + QuotedStr(ednohp.text) + ', alamat=' + QuotedStr(edalamat.text) +

',asal=' + QuotedStr(edlahir.text) + ', pekerjaan=' + QuotedStr(edkerja.text) + ', umur=' + QuotedStr(edumur.text) +

'WHERE noktp =' + QuotedStr(ednoktp.text);

adoquery1.ExecSQL;

reload();

end;

end;
procedure TForm2.btnnextClick(Sender: TObject);

begin

adoquery1.next;

tampil;

if adoquery1.eof then application.MessageBox('Data Terakhir', 'Info');

end;

procedure TForm2.btnprvClick(Sender: TObject);

begin

if not ADOquery1.Bof then

begin

ADOquery1.Prior;

tampil;

end

else

begin

application.MessageBox('Data Pertama', 'Info');

end;

end;

procedure TForm2.DBGrid1CellClick(Column: TColumn);

begin

if Adoquery1.RecordCount > 0 then tampil();

end;

procedure TForm2.DBGrid1KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);

begin

if Adoquery1.RecordCount > 0 then tampil();

end;
procedure TForm2.FormCreate(Sender: TObject);

begin

adoquery1.Active:= true;

end;

end.

You might also like