LISTING VB.NET
MenuUtama.vb Imports System.Data.OleDb Imports System.Data Public Class MenuUtama Private Sub MenuUtama_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try conn = New OleDbConnection(strconn) conn.Open() MessageBox.Show("Koneksi Sukses") Catch ex As Exception MsgBox("Koneksi ke Database Gagal", , "Error") MsgBox(ex.Message) Me.Dispose() End Try End Sub Private Sub BARANGToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BARANGToolStripMenuItem.Click FormBarang.Show() End Sub End Class
FormBarang.vb Public Class FormBarang Dim A As New ClassBarang Private Sub FormBarang_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load BukaKONEKSI() End Sub Sub KOSONG() TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click A.Kd = TextBox1.Text A.Tgl = TextBox2.Text A.Jml = TextBox3.Text A.simpan() KOSONG() End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click A.Kd = TextBox1.Text A.Tgl = TextBox2.Text A.Jml = TextBox3.Text A.ubah() KOSONG() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click A.Kd = TextBox1.Text A.Tgl = TextBox2.Text A.Jml = TextBox3.Text A.hapus() KOSONG() End Sub Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress If Asc(e.KeyChar) = 13 Then A.Kd = TextBox1.Text A.tampil() If A.NIL = 1 Then TextBox2.Text = A.Tgl TextBox3.Text = A.Jml End If End If End Sub End Class
ClassBarang.vb Imports System.Data.OleDb Imports System.Data Public Class ClassBarang #Region "Variabel" Private _Kd As String Private _Tgl As String Private _Jml As String Public NIL As Integer Dim Q As String = "" Dim Command As OleDbCommand Dim Read As OleDbDataReader Dim Hasrow As Boolean #End Region #Region "Property" Public Property Kd() As String Get Return _Kd End Get Set(ByVal value As String) _Kd = value
End Set End Property Public Property Tgl() As String Get Return _Tgl End Get Set(ByVal value As String) _Tgl = value End Set End Property Public Property Jml() As String Get Return _Jml End Get Set(ByVal value As String) _Jml = value End Set End Property #End Region #Region "Method" Public Function simpan() As Integer '-----LISTING UNTUK SIMPAN Q = "INSERT INTO BARANG VALUES('" & _Kd & "','" & _Tgl & "','" & _Jml & "')" Command = New OleDbCommand(Q, conn) Return Command.ExecuteNonQuery End Function Public Function ubah() As Integer '-----LISTING UNTUK UBAH Q = "update BARANG set Tgl='" & _Tgl & "', Jml='" & _Jml & "' where Kd='" & _Kd & "'" Command = New OleDbCommand(Q, conn) Return Command.ExecuteNonQuery End Function Public Function hapus() As Integer '-----LISTING UNTUK HAPUS Q = "delete from BARANG where Kd='" & _Kd & "'" Command = New OleDbCommand(Q, conn) Return Command.ExecuteNonQuery End Function #End Region #Region "Other Method" Public Function tampil() As Integer '-----MENAMPILKAN DATA BARANG DITEKS BCX NIL = 0 Command = New OleDbCommand("select * from BARANG where Kd='" & _Kd & "'", conn) Read = Command.ExecuteReader If Read.HasRows = True Then NIL = 1 Read.Read() _Kd = Read.Item(0) _Tgl = Read.Item(1) _Jml = Read.Item(2) End If End Function #End Region End Class
KONEKSI.vb Imports System.Data.OleDb Imports System.Data Module KONEKSI Public strconn As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & Application.StartupPath & "\Penjualan.accdb;" Public conn As OleDbConnection Sub BukaKONEKSI() conn = New OleDbConnection(strconn) If conn.State <> ConnectionState.Closed Then conn.Close() conn.Open() End Sub End Module