0% found this document useful (0 votes)
38 views2 pages

Data Barang

This document contains code for a program that manages product data in a database. It defines functions for saving, deleting, searching, editing, and displaying product data stored in a Microsoft Access database table called tbbarang. The functions connect to the database, execute the appropriate SQL statements, and return or display the results. When data is saved, deleted, or edited, it refreshes the display by retrieving an updated list of all products from the database table.

Uploaded by

Putri Amalia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views2 pages

Data Barang

This document contains code for a program that manages product data in a database. It defines functions for saving, deleting, searching, editing, and displaying product data stored in a Microsoft Access database table called tbbarang. The functions connect to the database, execute the appropriate SQL statements, and return or display the results. When data is saved, deleted, or edited, it refreshes the display by retrieving an updated list of all products from the database table.

Uploaded by

Putri Amalia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

DATA 

BARANG 

 
 
Imports System.Data 
Imports System.Data.OleDb 
 
Public Class FrBarang 
    Public koneksi As String 
    Public sql1, sql2, sql3, sql4, sql5 As String 
    Public conn As OleDb.OleDbConnection = Nothing 
    Public cmd As OleDb.OleDbCommand = Nothing 
    Public dtadapter As New OleDb.OleDbDataAdapter 
    Public dttable As New DataTable 
 
    Private Sub FrBarang_Load(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles MyBase.Load 
        koneksi = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Piksi 
Ganesha\barang\Barang.mdb" 
        conn = New OleDb.OleDbConnection(koneksi) 
        conn.Open() 
    End Sub 
 
    Sub simpan() 
        sql1 = "Insert into tbbarang values('" & Me.txtkode.Text & "','" & 
Me.txtnama.Text & "','" & Me.txtsatuan.Text & "','" & Me.txtharga.Text & "')" 
        cmd = New OleDb.OleDbCommand(sql1) 
        cmd.Connection = conn 
        cmd.ExecuteNonQuery() 
    End Sub 
 
    Sub delete() 
        Dim hapus As String 
        hapus = InputBox("Masukan Kode Barang", "Penghapusan") 
        sql4 = "delete from tbbarang where Kode_Barang = '" & hapus & "'" 
        cmd = New OleDb.OleDbCommand(sql4) 
        cmd.Connection = conn 
        cmd.ExecuteNonQuery() 
    End Sub 
    Sub cari() 
        Dim cari As String 
        cari = InputBox("Masukan Kode Barang", "Pencarian") 
        sql3 = "select * from tbbarang where Kode_Barang = '" & cari & "'" 
        dtadapter = New OleDbDataAdapter(sql3, conn) 
        Dim BRG As New DataTable 
        BRG.Clear() 
        dtadapter.Fill(BRG) 
        Dgvbarang.DataSource = BRG 
    End Sub 
 
    Sub edit() 
        sql5 = "update tbbarang set Nama_Barang = '" & txtnama.Text & "', Satuan = '" 
& txtsatuan.Text & "', Harga = '" & txtharga.Text & "' where Kode_Barang = '" & 
txtkode.Text & "'" 
        cmd = New OleDb.OleDbCommand(sql5) 
        cmd.Connection = conn 
        cmd.ExecuteNonQuery() 
    End Sub 
 
    Sub bersih() 
        Me.txtkode.Focus() 
        Me.txtnama.Text = "" 
        Me.txtsatuan.Text = "" 
        Me.txtharga.Text = "" 
    End Sub 
 
    Sub daftar() 
        sql2 = "select * from tbbarang" 
        dtadapter = New OleDbDataAdapter(sql2, conn) 
        Dim BRG As New DataTable 
        BRG.Clear() 
        dtadapter.Fill(BRG) 
        Dgvbarang.DataSource = BRG 
    End Sub 
 
    Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles btnsave.Click 
        simpan() 
        daftar() 
        bersih() 
        MsgBox("Data Sudah Disimpan", MsgBoxStyle.Information, "Perhatian") 
    End Sub 
 
    Private Sub btnhapus_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles btnhapus.Click 
        delete() 
        daftar() 
        MsgBox("Data Telah Terhapus", MsgBoxStyle.Information, "Informastion") 
    End Sub 
 
    Private Sub btncari_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles btncari.Click 
        cari() 
    End Sub 
 
    Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles btnupdate.Click 
        edit() 
        daftar() 
        MsgBox("Data Telah Terupdate", MsgBoxStyle.Information, "Informastion") 
    End Sub 
End Class 
 

You might also like