Langkah-langkah membuat dan menyimpan data sebagai berikut :
- Buka SQL Server Enterprise Manager, pada database ‘coba’, buat table ‘tb_brg’ dan isi dengan kolom seperti ini
- Buat form seperti berikut yang berisi : Adoconnectio (tab Ado), 2 adoquery (tab ADO), 1 datasource (tab data access) dan dbgrid (tab data Control).
- Tahap berikutnya klik datasource1, pada properties sambungkan dataset => qr_view (adoquery2), yang berfungsi untuk menyambungkan adoquery==>Dbgrid. Klik DBGrid sambungkan datasource==>Datasource1.
- Lahkah selanjutnya, isikan sintak pada tiap button :
Button Koneksi :
+++++++++++++++++ START SOURCE +++++++++++++++++
trywith ADOConnection1 do begin Connected:=false; ConnectionString:='Provider='+Edit1.Text+'.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog='+Edit2.Text; LoginPrompt:=false; Connected:=true; end; ShowMessage('koneksi Sukses dab...'); except begin ShowMessage('Gagal Bro....'+#13+'Ulangi lagi yah...'); Edit1.SetFocus; end; end;
+++++++++++++++++ END CODE +++++++++++++++++
+++++++++++++++++ START SOURCE +++++++++++++++++
if (edit3.Text<>'') and (edit4.Text<>'') and (edit5.Text<>'') and (edit6.Text<>'') then begin try ADOConnection1.BeginTrans; with qr_free do begin Active:=False; sql.Clear; close; Connection:=ADOConnection1; sql.Add('Insert into tb_brg values('+QuotedStr(edit3.Text)+','+QuotedStr(edit4.Text)+','+Edit5.Text+','+Edit6.Text+')'); ExecSQL; end; ADOConnection1.CommitTrans; ShowMessage('berhasil simpan'); except ADOConnection1.RollbackTrans; ShowMessage('Gagal simpan'); end; end else ShowMessage('Ups!!! Edit diisi doeloe donk...'); +++++++++++++++++ END CODE +++++++++++++++++
+++++++++++++++++ START SOURCE +++++++++++++++++
try With qr_view do begin Active:=false; sql.Clear; close; Connection:=ADOConnection1; sql.Add('Select * from tb_brg'); Active:=true; end; with DBGrid1 do begin Columns.Items[0].FieldName:='kd_brg'; Columns.Items[1].FieldName:='nm_brg'; Columns.Items[2].FieldName:='hrg_beli'; Columns.Items[3].FieldName:='hrg_jual'; end; except begin ShowMessage('Mungkin Belum Koneksi, silahkan Koneksi dulu yah?'); edit1.SetFocus; end; end;
Sekian dulu yah…
mau ujian PW.WKWKWK
Post a Comment