Deskripsi Form Latihan 33A
Pada form
latihan 33A ada 3 object yang digunakan yaitu Label, Data Grid View dan Button.
Object Label
object
label yang digunakan ada 1 (daftar barang).
Object DataGridView
Object datagridview yang berfungsi untuk
menampilkan data tabel.
Object Button
Terdapat 3
object button (hapus, edit dan tambah). Tombol tambah berfungsi untuk menambah
data dengan menampilkan form “Latihan_33B_46110002. Tombol edit digunakan untuk
mengedit data dimana perintahnya terdapat pada form “Latihan_33B_46110002”.
Tombol hapus untuk menghapus.
Even
Load
Click
Script Unique
Pada Latihan ini
tidak ada script yang baru, secara keseluruhan script telah ada pada
latihan-latihan sebelumnya.
Langkah-Langkah
Penyelesaian Form Latihan_33A_46110002
·
Buka folder project yang telah dibuat.
·
Klik kanan, view kode lalu masukkan rumus
Public Class Latihan_33A_46110002
Dim Jalan As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" & Application.StartupPath & "\DataBarang.ACCDB")
Dim ambil As New DataTable
Public Sub ambildata()
Dim data As New OleDb.OleDbDataAdapter
data = New OleDb.OleDbDataAdapter("SELECT* FROM barang", Jalan)
ambil.Rows.Clear()
data.Fill(ambil)
data.Dispose()
End Sub
Private Sub Latihan_33A_46110002_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ambildata()
DGV_46110002.DataSource = ambil
End Sub
Private Sub TAMBAH_46110002_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TAMBAH_46110002.Click
If Latihan_33B_46110002.Visible = False Then
Latihan_33B_46110002.Show()
Else
Latihan_33B_46110002.Activate()
End If
Latihan_33B_46110002.GANTI_46110002.Text = "-"
Latihan_33B_46110002.KB_46110002.Text = " "
Latihan_33B_46110002.NB_46110002.Text = " "
Latihan_33B_46110002.HJ_46110002.Text = " "
Latihan_33B_46110002.JB_46110002.Text = " "
End Sub
Private Sub EDIT_46110002_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EDIT_46110002.Click
If Latihan_33B_46110002.Visible = False Then
Latihan_33B_46110002.Show()
Else
Latihan_33B_46110002.Activate()
End If
Latihan_33B_46110002.GANTI_46110002.Text = DGV_46110002.CurrentRow.Cells("kodebarang").Value
Latihan_33B_46110002.KB_46110002.Text = DGV_46110002.CurrentRow.Cells("kodebarang").Value
Latihan_33B_46110002.NB_46110002.Text = DGV_46110002.CurrentRow.Cells("namabarang").Value
Latihan_33B_46110002.HJ_46110002.Text = DGV_46110002.CurrentRow.Cells("hargajual").Value
Latihan_33B_46110002.JB_46110002.Text = DGV_46110002.CurrentRow.Cells("JumlahBarang").Value
End Sub
Private Sub HAPUS_46110002_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HAPUS_46110002.Click
If MsgBox("Seriously you want to delete the data???", MsgBoxStyle.YesNo) = MsgBoxResult.No Then
Exit Sub
End If
Dim Cm As New OleDb.OleDbCommand
Cm = New OleDb.OleDbCommand(" delete * from barang where kodebarang ='" & DGV_46110002.CurrentRow.Cells("Kodebarang").Value & "'", Jalan)
Jalan.Open()
Cm.ExecuteNonQuery()
Jalan.Close()
Cm.Dispose()
ambildata()
End Sub
End Class
Public Class Latihan_33A_46110002
Dim Jalan As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" & Application.StartupPath & "\DataBarang.ACCDB")
Dim ambil As New DataTable
Public Sub ambildata()
Dim data As New OleDb.OleDbDataAdapter
data = New OleDb.OleDbDataAdapter("SELECT* FROM barang", Jalan)
ambil.Rows.Clear()
data.Fill(ambil)
data.Dispose()
End Sub
Private Sub Latihan_33A_46110002_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ambildata()
DGV_46110002.DataSource = ambil
End Sub
Private Sub TAMBAH_46110002_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TAMBAH_46110002.Click
If Latihan_33B_46110002.Visible = False Then
Latihan_33B_46110002.Show()
Else
Latihan_33B_46110002.Activate()
End If
Latihan_33B_46110002.GANTI_46110002.Text = "-"
Latihan_33B_46110002.KB_46110002.Text = " "
Latihan_33B_46110002.NB_46110002.Text = " "
Latihan_33B_46110002.HJ_46110002.Text = " "
Latihan_33B_46110002.JB_46110002.Text = " "
End Sub
Private Sub EDIT_46110002_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EDIT_46110002.Click
If Latihan_33B_46110002.Visible = False Then
Latihan_33B_46110002.Show()
Else
Latihan_33B_46110002.Activate()
End If
Latihan_33B_46110002.GANTI_46110002.Text = DGV_46110002.CurrentRow.Cells("kodebarang").Value
Latihan_33B_46110002.KB_46110002.Text = DGV_46110002.CurrentRow.Cells("kodebarang").Value
Latihan_33B_46110002.NB_46110002.Text = DGV_46110002.CurrentRow.Cells("namabarang").Value
Latihan_33B_46110002.HJ_46110002.Text = DGV_46110002.CurrentRow.Cells("hargajual").Value
Latihan_33B_46110002.JB_46110002.Text = DGV_46110002.CurrentRow.Cells("JumlahBarang").Value
End Sub
Private Sub HAPUS_46110002_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HAPUS_46110002.Click
If MsgBox("Seriously you want to delete the data???", MsgBoxStyle.YesNo) = MsgBoxResult.No Then
Exit Sub
End If
Dim Cm As New OleDb.OleDbCommand
Cm = New OleDb.OleDbCommand(" delete * from barang where kodebarang ='" & DGV_46110002.CurrentRow.Cells("Kodebarang").Value & "'", Jalan)
Jalan.Open()
Cm.ExecuteNonQuery()
Jalan.Close()
Cm.Dispose()
ambildata()
End Sub
End Class
Langkah-Langkah
Menjalankan Form Latihan 33
·
Klik star debugging, trus klik latihan 33
·
Lalu click “TAMBAH ATAU EDIT” maka akan muncul
latihan 33B
·
Click “simpan” untuk menyimpan data yang telah ditambah atau diedit.







0 komentar:
Posting Komentar