Form Latihan_34b_36110037 terdapat Tiga object yaitu label, data grid view, dan button.

Object Data Grid View 

Terdapat sebuah object Data Grid View yang bernama Kertas_36110037.

Object Label
Terdapat sebuah object Label yang bernama bertuliskan “daftar barang”.

Object Button
Terdapat Tiga object button yaitu button hapus yang digunakan untuk menghapus row atau baris yang dipilih di datatable pada datagridview. Kemudian button tambah digunakan untuk membuka latihan_33b_36110037 yang  berfungsi untuk menambah data yang diinput ke database lalu ditampakkan di datatable pada datagridview. Sedangkan Button edit digunakan untuk membuka latihan_33b_36110037 yang  berfungsi untuk mengubah data yang diinput ke database lalu ditampakkan di datatable pada datagridview.
Script Unique

Saat mengklik button hapus
Dim rpm As String = "delete * from barang where kodebarang = '" & kertas_36110037.CurrentRow.Cells("kodebarang").Value & "'"

Saat mengklik button tambah
If Latihan_34c_36110037.Visible = False Then
         Latihan_34c_36110037.Show()
   Else
         Latihan_34c_36110037.Activate()
End If

Saat mengklik button edit
If Latihan_34c_36110037.Visible = False Then
            Latihan_34c_36110037.Show()
        Else
            Latihan_34c_36110037.Activate()
        End If
        Latihan_34c_36110037.kbl_36110037.Text = kertas_36110037.CurrentRow.Cells("kodebarang").Value
        Latihan_34c_36110037.kb_36110037.Text = kertas_36110037.CurrentRow.Cells("kodebarang").Value
        Latihan_34c_36110037.nb_36110037.Text = kertas_36110037.CurrentRow.Cells("namabarang").Value
        Latihan_34c_36110037.jb_36110037.Text = kertas_36110037.CurrentRow.Cells("jumlahbarang").Value
        Latihan_34c_36110037.hj_36110037.Text = kertas_36110037.CurrentRow.Cells("hargajual").Value

Event
Buttonclick

Property
Default


Prosedur Penyelesaian
1. buka project yang telah dibuat.
2. buka Solution explorer.
3. setelah itu klik kanan nama project, pilih add dan klik new item.

4. setelah add new item terbuka, pilih windows form, windoes form, kemudian ketik nama form, dan add.
 
5. buat form seperti di bawah ini dengan menggunakan toolbox.
 
6. setelah form selesai, ubah nama textbox dan button menggunakan properties window
 
7. setelah itu, masuk ke lembar "vb" dengan cara mengklik 2x form dan kemudian ketikkan formula berikut.
 Public Class Latihan_34b_36110037
    Dim rhepoet As New DataTable
    Dim resky As New OleDb.OleDbCommand
    Dim keren As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='D:\Rhepoet\Kampuz\Semester 5\Apkom 4\LATIHAN 27-34 SIMPAN EDIT DELETE DATA\DATABARANG.accdb'")
    Private Sub Latihan_34b_36110037_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim adapter As New OleDb.OleDbDataAdapter
        adapter = New OleDb.OleDbDataAdapter("select * from barang", keren)
        rhepoet.Rows.Clear()
        adapter.Fill(rhepoet)
        adapter.Dispose()
        kertas_36110037.DataSource = rhepoet
    End Sub

    Private Sub hapus_36110037_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles hapus_36110037.Click
        Dim rpm As String = "delete * from barang where kodebarang = '" & kertas_36110037.CurrentRow.Cells("kodebarang").Value & "'"
        resky = New OleDb.OleDbCommand(rpm, keren)
        keren.Open()
        resky.ExecuteNonQuery()
        keren.Close()
        resky.Dispose()

        Dim adapter As New OleDb.OleDbDataAdapter
        adapter = New OleDb.OleDbDataAdapter("select * from barang", keren)
        rhepoet.Rows.Clear()
        adapter.Fill(rhepoet)
        adapter.Dispose()
        kertas_36110037.DataSource = rhepoet
    End Sub

    Private Sub tambah_36110037_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles tambah_36110037.Click
        If Latihan_34c_36110037.Visible = False Then
            Latihan_34c_36110037.Show()
        Else
            Latihan_34c_36110037.Activate()
        End If
    End Sub

    Private Sub edit_36110037_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles edit_36110037.Click
        If Latihan_34c_36110037.Visible = False Then
            Latihan_34c_36110037.Show()
        Else
            Latihan_34c_36110037.Activate()
        End If
        Latihan_34c_36110037.kbl_36110037.Text = kertas_36110037.CurrentRow.Cells("kodebarang").Value
        Latihan_34c_36110037.kb_36110037.Text = kertas_36110037.CurrentRow.Cells("kodebarang").Value
        Latihan_34c_36110037.nb_36110037.Text = kertas_36110037.CurrentRow.Cells("namabarang").Value
        Latihan_34c_36110037.jb_36110037.Text = kertas_36110037.CurrentRow.Cells("jumlahbarang").Value
        Latihan_34c_36110037.hj_36110037.Text = kertas_36110037.CurrentRow.Cells("hargajual").Value
    End Sub
End Class
8. Uji program dengan mengklik "Start Debugging".
9. Save program dengan mengklik icon "save".
 
10. Selesai.
Diposting oleh Unknown

0 komentar:

Visit the Site
MARVEL and SPIDER-MAN: TM & 2007 Marvel Characters, Inc. Motion Picture © 2007 Columbia Pictures Industries, Inc. All Rights Reserved. 2007 Sony Pictures Digital Inc. All rights reserved. blogger template by blog forum.