Membuat program database dengan menggunakan adodc dan data grid
1.buatlah
tampilan form seperti dibawah ini :
2. klik pada command 1 lalu ganti name = command 1 menjadi
cmd_tambah dan caption menjadi tambah,begitu juga dengan command2 menjadi ubah ,command3
menjadi hapus dan command4 menjadi keluar.
3.klik kanan
pada adodc lalu pilih adodc properties,klik recordsource kemudian klik build,
select database name yang telah di buat yaitu akademik_anggie klik open lalu
klik test connection.
4. untuk
menampilkan tulisan kode jurusan dan nama jurusan klik kanan pda data grid lalu
pilih retieve fields, pada properties klik record source pilih adodc1.
5.masukan codingan
Private Sub
form_load()
Adodc1.ConnectionString
= "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data
Source=C:\Users\Agung\Documents\akademik anggie.mdb"
Adodc1.RecordSource = "Select *from Jurusan"
'Adodc1.Refresh
DataGrid1.Refresh
Adodc1.RecordSource = "Select *from Jurusan"
'Adodc1.Refresh
DataGrid1.Refresh
Adodc2.ConnectionString
= "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data
Source=C:\Users\Agung\Documents\akademik anggie.mdb"
Adodc2.RecordSource = "Select *from Jurusan"
Adodc2.Refresh
End Sub
Private Sub bersih()
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End Sub
Private Sub normal()
cmd_tambah.Caption = "&Tambah"
Cmd_ubah.Caption = "&Ubah"
Cmd_hapus.Caption = "&Hapus"
Cmd_keluar.Caption = "&Keluar"
Cmd_tambah.Enabled = True
cmd_ubah.Enabled = True
Cmd_hapus.Enabled = True
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Adodc2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Users\Agung\Documents\akademik anggie.mdb"
Adodc2.RecordSource = "Select *from Jurusan where Kode_Jurusan = '" & Trim(Text1.Text) & "'"
Adodc2.Refresh
If Not Adodc2.Recordset.EOF Then
If Cmd_tambah.Caption = "&Simpan" Then
MsgBox "Data sudah ada"
Text1.SetFocus
Else
Text2.Text = Adodc2.Recordset("Nama_Jurusan")
Text2.SetFocus
End If
Else
If Cmd_tambah.Caption = "&Simpan" Then
Text2.SetFocus
Else
MsgBox "Data sudah ada"
Text1.SetFocus
End If
End If
End If
End Sub
Private Sub Cmd_tambah_Click()
Adodc2.RecordSource = "Select *from Jurusan"
Adodc2.Refresh
End Sub
Private Sub bersih()
Text1.Text = ""
Text2.Text = ""
Text1.SetFocus
End Sub
Private Sub normal()
cmd_tambah.Caption = "&Tambah"
Cmd_ubah.Caption = "&Ubah"
Cmd_hapus.Caption = "&Hapus"
Cmd_keluar.Caption = "&Keluar"
Cmd_tambah.Enabled = True
cmd_ubah.Enabled = True
Cmd_hapus.Enabled = True
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Adodc2.ConnectionString = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=C:\Users\Agung\Documents\akademik anggie.mdb"
Adodc2.RecordSource = "Select *from Jurusan where Kode_Jurusan = '" & Trim(Text1.Text) & "'"
Adodc2.Refresh
If Not Adodc2.Recordset.EOF Then
If Cmd_tambah.Caption = "&Simpan" Then
MsgBox "Data sudah ada"
Text1.SetFocus
Else
Text2.Text = Adodc2.Recordset("Nama_Jurusan")
Text2.SetFocus
End If
Else
If Cmd_tambah.Caption = "&Simpan" Then
Text2.SetFocus
Else
MsgBox "Data sudah ada"
Text1.SetFocus
End If
End If
End If
End Sub
Private Sub Cmd_tambah_Click()
If Cmd_tambah.Caption = "&Tambah" Then
Call bersih
Cmd_tambah.Caption = "&Simpan"
Cmd_ubah.Enabled = False
Cmd_hapus.Enabled = False
Cmd_keluar.Caption = "&Batal"
Else
Adodc1.Recordset.AddNew
Adodc1.Recordset("Kode_Jurusan") =
Trim(Text1.Text)
Adodc1.Recordset("Nama_Jurusan") =
Trim(Text2.Text)
Adodc1.Recordset.Update
'Adodc1.Refresh
DataGrid1.Refresh
'Adodc1.Refresh
DataGrid1.Refresh
Call bersih
Call normal
End If
End Sub
Private Sub Cmd_ubah_Click()
If Cmd_ubah.Caption = "&Ubah" Then
Call bersih
Cmd_ubah.Caption = "&Simpan"
Cmd_tambah.Enabled = False
Cmd_hapus.Enabled = False
Cmd_keluar.Caption = "&Batal"
Else
Adodc2.RecordSource = "Select *from Jurusan
where Kode_Jurusan = '" & Trim(kode_jurusan) & "'"
Adodc2.Refresh
Adodc1.Recordset("Nama_Jurusan") =
Trim(Text2.Text)
Adodc1.Recordset.Update
‘Adodc1.Refresh
DataGrid1.Refresh
End If
End Sub
Private Sub Cmd_hapus_Click()
If Cmd_hapus.Caption = "&Hapus" Then
Call bersih
Cmd_hapus.Caption = "&Oke"
Cmd_tambah.Enabled = False
Cmd_ubah.Enabled = False
Command4.Caption = "&Batal"
Else
Adodc2.RecordSource = "Select *from Jurusan where Kode_Jurusan = '" & Trim(kode_jurusan) & "'"
Adodc2.Refresh
Adodc1.Recordset("Nama_Jurusan") = Trim(Text2.Text)
Adodc1.Recordset.Delete
'Adodc1.Refresh
DataGrid1.Refresh
End If
End Sub
Private Sub Cmd_keluar_Click()
If Cmd_keluar.Caption = "&Keluar" Then
Unload Me
Else
Call bersih
Call normal
End If
End Sub
If Cmd_hapus.Caption = "&Hapus" Then
Call bersih
Cmd_hapus.Caption = "&Oke"
Cmd_tambah.Enabled = False
Cmd_ubah.Enabled = False
Command4.Caption = "&Batal"
Else
Adodc2.RecordSource = "Select *from Jurusan where Kode_Jurusan = '" & Trim(kode_jurusan) & "'"
Adodc2.Refresh
Adodc1.Recordset("Nama_Jurusan") = Trim(Text2.Text)
Adodc1.Recordset.Delete
'Adodc1.Refresh
DataGrid1.Refresh
End If
End Sub
Private Sub Cmd_keluar_Click()
If Cmd_keluar.Caption = "&Keluar" Then
Unload Me
Else
Call bersih
Call normal
End If
End Sub
6.maka tampilan running seperti
dibawah ini
a.tambah->simpan,ubah dan hapus tidak aktif,keluar->batal
a.tambah->simpan,ubah dan hapus tidak aktif,keluar->batal
b.running ubah
ubah -> simpan,tambah dan hapus
tidak aktif ,keluar-> batal
c.running hapus
hapus->simpan, tambah dan ubah
tidak aktif ,keluar -> batal
d.running batal
kembali ke posisi normal ,yaitu tambah
ubah hapus keluar aktif semua
e.running keluar
program akhir















<





