Berikut adalah cara membuat proses CRUD ( Create , Read, Update, Delete ) pada Visual Foxpro :
1. Buat table seperti gambar dibawah ini : tblharga.dbf yang terdiri dari fields :
kode ( kode barang ), nama ( nama barang ) dan harga
2. Design Form seperti gambar dibawah :
3. Tambahkan script pada masing-masing object control yang terkait :
3.1. Object Form
Object Form1 Procedure InitSET TALK OFFSET DELETE onSET EXCLUSIVE onSET EXACT ONIF !USED("tblharga")SELECT 1USE tblharga EXCLUSIVEENDIFthisform.txtkode.Value =''thisform.txtnama.Value =''thisform.txtharga.Value =0thisform.txtnama.Enabled = .F.thisform.txtharga.Enabled = .F.thisform.cmdsave.Enabled = .F.thisform.cmdedit.Enabled = .F.thisform.cmddelete.Enabled = .F.thisform.txtkode.SetFocusObject Form1 procedure LoadPUBLIC barubaru =0
3.2. Object Command Save
Object cmdsave procedure click
IF EMPTY(thisform.txtkode.Value)
=MESSAGEBOX("Kode Barang belum diisi",0+64,"Info")
RETURN
ENDIF
IF EMPTY(thisform.txtnama.Value)
=MESSAGEBOX("Nama Barang belum diisi",0+64,"Info")
RETURN
ENDIF
IF EMPTY(thisform.txtharga.Value)
=MESSAGEBOX("Harga Barang belum diisi",0+64,"Info")
RETURN
ENDIF
SELECT tblharga
SET ORDER To tag kode
kdb=ALLTRIM(thisform.txtkode.Value)
nmb=ALLTRIM(thisform.txtnama.Value)
hb= thisform.txtharga.Value
IF baru=0
INSERT INTO tblharga(kode,nama,harga) values(kdb,nmb,hb)
ELSE
UPDATE tblharga set nama=nmb,harga=hb WHERE kode=kdb
ENDIF
thisform.cmdcancel.Click
3.3. Object Command Edit
Object cmdedit procedure click
this.Enabled = .F.
thisform.cmdsave.Enabled = .T.
baru = 1
thisform.txtkode.Enabled = .F.
thisform.txtnama.Enabled = .T.
thisform.txtharga.Enabled = .T.
thisform.txtnama.SetFocus
3.4. Object Command Delete
Object cmddelete procedure click
IF MESSAGEBOX("Data ini mau dihapus?",4+32,"Konfirmasi")=7
thisform.cmdcancel.Click
ENDIF
SELECT tblharga
SET ORDER TO tag kode
DELETE
thisform.cmdcancel.Click
3.5. Object Command Cancel
Object cmdcancel procedure click
thisform.txtkode.Value =''
thisform.txtnama.Value =''
thisform.txtharga.Value =0
thisform.txtnama.Enabled = .F.
thisform.txtharga.Enabled = .F.
thisform.cmdsave.Enabled = .F.
thisform.cmdedit.Enabled = .F.
thisform.cmddelete.Enabled = .F.
thisform.Refresh
thisform.txtkode.Enabled = .T.
thisform.txtkode.SetFocus
3.6. Object Command Exit
Object cmdexit procedure click
thisform.Release
Layout, silahkan lakukan proses CRUD