Penggunaan insert update delete di Delphi by xenor88

VIEWS: 248 PAGES: 4

Contoh program Penggunaan insert update delete di Delphi

More Info
									                         Penggunaan SQL UPDATE, INSERT, DELETE pada Delphi




Perintah Insert

procedure Tf_input_data_mhs.Button1Click(Sender: TObject);

begin

if (edit_nim.Text <>'') and (edit_nama.text<>'') and (edit_tp_lhr.Text<>'') then

  begin

   try dm.ADOConnection1.BeginTrans;

    with dm.qry_kosong do

        begin

        close;

         sql.Clear;

         sql.Add('insert into tb_mhs values('+quotedstr(edit_nim.text)+','

        +quotedstr(edit_nama.text)+','+quotedstr(edit_tp_lhr.text)+','

        +quotedstr(formatdatetime('yyyy-mm-dd',dp_tgl_lhr.Date))+')');
         ExecSQL;

         showmessage('sukses');

         edit_nim.Clear;

         edit_nama.Text:='';

         edit_tp_lhr.Text:='';

         edit_nim.SetFocus;

        end;

        dm.ADOConnection1.CommitTrans;

        dm.query_mhs.Requery();

   except dm.ADOConnection1.RollbackTrans;

       showmessage('data sudah ada');

   end;

  end;

end;

Perintah Update

procedure Tf_input_data_mhs.Button2Click(Sender: TObject);

begin

   try dm.ADOConnection1.BeginTrans;

    with dm.qry_kosong do

        begin

         close;

         sql.Clear;

         sql.Add('update tb_mhs set');

         sql.Add('nama='+quotedstr(edit_nama.text)+',');

         sql.Add('alamat='+quotedstr(edit_tp_lhr.text)+',');

         sql.Add('tgl_lhr='+quotedstr(formatdatetime('yyyy-mm-dd',dp_tgl_lhr.Date))+' ');

         sql.Add('where nim='+quotedstr(edit_nim.Text));
         ExecSQL;

         showmessage('data telah diupdate');

         edit_nim.Clear;

         edit_nama.Text:='';

         edit_tp_lhr.Text :='';

         edit_nim.SetFocus;

        end;

        dm.ADOConnection1.CommitTrans;

        dm.query_mhs.Requery();

   except dm.ADOConnection1.RollbackTrans;

       showmessage('data gagal diupdate');

   end;

end;

Perintah Delete

procedure Tf_input_data_mhs.Button3Click(Sender: TObject);

begin

   try dm.ADOConnection1.BeginTrans;

    with dm.qry_kosong do

        begin

         close;

         sql.Clear;

         sql.Add('delete from tb_mhs where nim='+quotedstr(edit_nim.Text));

         ExecSQL;

         showmessage('data telah diupdate');

         edit_nim.Clear;

         edit_nama.Text:='';

         edit_tp_lhr.Text :='';
         edit_nim.SetFocus;

        end;

        dm.ADOConnection1.CommitTrans;

        dm.query_mhs.Requery();

   except dm.ADOConnection1.RollbackTrans;

       showmessage('data gagal diupdate');

   end;

end;

								
To top