You are on page 1of 2

Imports System.Data.OleDb Public Class Form1 Private Sub TampilData() Using Conn As New OleDbConnection(My.Settings.

ConnStr) Using Adp As New OleDbDataAdapter( Select * From tblBarang , Conn) Conn.Open() Dim Tabel As New DataTable Adp.Fill(Tabel) DataGridView1.DataSource = Tabel End Using End Using End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Event Args) Handles Button1.Click Dim Tambah As String = Insert Into tblBarang Values( & TextBox1.Text & , & TextBox2.Te t & , & TextBox3.Text & , & TextBox4.Text & , & TextBox5.Text & ) Try Using Conn As New OleDbConnection(My.Settings.ConnStr) Using cmd As New OleDbCommand(Tambah, Conn) Conn.Open() cmd.ExecuteNonQuery() MsgBox( Data Berhasil Ditambah , MsgBoxStyle.Information, Perhatian ) TampilData() End Using End Using Catch ex As Exception MsgBox(ex.Message) End Try End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.Event Args) Handles Button2.Click Dim Ubah As String = Update tblBarang Set NamaBarang= & TextBox2.Text & , HargaBeli= & TextBox3.Text & ,HargaJual= & TextBox4.Text & ,Jumlah= & TextBox5.Text & Where Kod = & TextBox1.Text & Try Using Conn As New OleDbConnection(My.Settings.ConnStr) Using cmd As New OleDbCommand(Ubah, Conn) Conn.Open() cmd.ExecuteNonQuery() MsgBox( Data Berhasil DiUbah , MsgBoxStyle.Information, Perhatian ) TampilData() End Using End Using Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.Event Args) Handles Button3.Click Dim Hapus As String = Delete From tblBarang Where KodeBarang= & TextBox1.Text & Try Using Conn As New OleDbConnection(My.Settings.ConnStr) Using cmd As New OleDbCommand(Hapus, Conn) Conn.Open() cmd.ExecuteNonQuery() MsgBox( Data Berhasil Dihapus , MsgBoxStyle.Information, Perhatian )

TampilData() End Using End Using Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.Event Args) Handles Button4.Click End End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load TampilData() End Sub End Class

You might also like