// Kode Untuk Class: dipanggil melalui form kerja.
Imports System.Data
Imports System.Data.OleDb
Namespace AccessData
Public Class AccessBarang
Public Function AccessBarangInsert(ByVal Kode_Brg As String, _
ByVal Deskripsi As String, _
ByVal Path As String, ByVal Stok As String, _
ByVal Hrg_Beli As String, _
ByVal Hrg_Jual As String, ByVal Minimum As String)
Dim myCmd As New OleDbCommand
Dim myconnection As New AccessData.DatabaseConnection
myCmd.CommandText = "Insert INTO Barang" _
& " (Kode_Brg,Deskripsi,Path,Stok,Hrg_Beli,Hrg_Jual,Minimum) Values (" _
& "' & Kode_Brg & "','" & Deskripsi & "','" & Path & "','" & Stok & "'," & _
" '" & Hrg_Beli & "','" & Hrg_Jual & "','" & Minimum & "') "
myCmd.Connection = myconnection.open
myCmd.ExecuteNonQuery()
myconnection.close()
End Function
------------------------------------------------------------------------------------------------------------------------------
Public Function AccessBarangUpdate(ByVal Kode_Brg As String, _
ByVal Deskripsi As String, ByVal Path As String, _
ByVal Stok As String, ByVal Hrg_Beli As String, _
ByVal Hrg_Jual As String, ByVal Minimum As String)
Dim myCmd As New OleDbCommand
Dim myconnection As New AccessData.DatabaseConnection
myCmd.CommandText = "Update Barang Set " _
& " Deskripsi='" & Deskripsi & "'," _
& " Path='" & Path & "',Stok='" & Stok & "', " & _
" Hrg_Beli='" & Hrg_Beli & "'," _
& " Hrg_Jual='" & Hrg_Jual & "',Minimum='" & Minimum & "'" _
& " Where Kode_Brg='" & Kode_Brg & "' "
myCmd.Connection = myconnection.open
myCmd.ExecuteNonQuery()
myconnection.close()
End Function
----------------------------------------------------------------------------------------------------------------------------
Public Function AccessBarangUpdateStok(ByVal Kode_Brg As String, _
ByVal Stok As String)
Dim myCmd As New OleDbCommand
Dim myconnection As New AccessData.DatabaseConnection
myCmd.CommandText = "Update Barang Set " _
& " Stok='" & Stok & "'" _
& " Where Kode_Brg='" & Kode_Brg & "' "
myCmd.Connection = myconnection.open
myCmd.ExecuteNonQuery()
myconnection.close()
End Function
--------------------------------------------------------------------------------------------------------------
Public Function AccessBarangDelete(ByVal Kode_Brg As String)
Dim myCmd As New OleDbCommand
Dim myconnection As New AccessData.DatabaseConnection
myCmd.CommandText = "Delete From Barang where " & _
" Kode_Brg='" & Kode_Brg & "' "
myCmd.Connection = myconnection.open
myCmd.ExecuteNonQuery()
myconnection.close()
End Function
End Class
End Namespace
--------------------------------------------------------------------------------------------------------------------------
untuk memanggil kode dari class di atas maka tambahkan kode berikut pada form kerja didalam sebuah region:
#Region "Deklarasi"
Dim MyConnection As New AccessData.DatabaseConnection
Dim objConnection As OleDbConnection
Dim objCommand As OleDbCommand
Dim objDataAdapter As OleDbDataAdapter
Dim objdatareader As OleDbDataReader
Dim strSQL, mProcess As String
Dim objDataSet As New DataSet
Dim objDataTable As New DataTable
Dim Stok As Integer
Protected MyConnectionPembelian As New AccessData.AccessPembelian
Protected MyConnectionTotalPembelian As New AccessData.AccessTotalPembelian
Protected MyConnectionBarang As New AccessData.AccessBarang
#End Region