MANAJEMEN DATABASE VISUAL STUDIO 2008

DENGAN MICROSOFT ACCESS



DATABASE PERPUSTAKAAN



Oleh:
Candra Mecca Sufyana S.Si., MT








Imports System.Data
Imports System.Data.OleDb

Public Class frbuku
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 frbuku_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
koneksi = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=|DataDirectory|\dbperpustakaan.mdb"
conn = New OleDb.OleDbConnection(koneksi)
conn.Open()
End Sub
Sub bersih()
Me.txtkodebuku.Focus()
Me.txtjudul.Text = ""
Me.txtpengarang.Text = ""
Me.txtpenerbit.Text = ""
End Sub

Sub simpan()
sql1 = "Insert into tbbuku values('" & Me.txtkodebuku.Text & "','"
& Me.txtjudul.Text & "','" & Me.txtpengarang.Text & "','" &
Me.txtpenerbit.Text & "')"
cmd = New OleDb.OleDbCommand(sql1)
cmd.Connection = conn
cmd.ExecuteNonQuery()
End Sub

Sub daftar()
sql2 = "select * from tbbuku"
dtadapter = New OleDbDataAdapter(sql2, conn)
Dim BRG As New DataTable
BRG.Clear()
dtadapter.Fill(BRG)
DgvBuku.DataSource = BRG
End Sub
Sub cari()
Dim cari As String
cari = InputBox("Masukan Kode Buku", "Pencarian")
sql3 = "select * from tbbuku where Kode_Buku = '" & cari & "'"
dtadapter = New OleDbDataAdapter(sql3, conn)
Dim CST As New DataTable
CST.Clear()
dtadapter.Fill(CST)
DgvBuku.DataSource = CST
End Sub
Sub delete()
Dim hapus As String
hapus = InputBox("Masukan Kode Buku", "Penghapusan")
sql4 = "delete from tbbuku where Kode_Buku = '" & hapus & "'"
cmd = New OleDb.OleDbCommand(sql4)
cmd.Connection = conn
cmd.ExecuteNonQuery()
End Sub
Sub edit()
sql5 = "update tbbuku set Judul = '" & txtjudul.Text & "',
Pengarang = '" & txtpengarang.Text & "', Penerbit = '" & txtpenerbit.Text &
"' where Kode_Buku = '" & txtkodebuku.Text & "'"
cmd = New OleDb.OleDbCommand(sql5)
cmd.Connection = conn
cmd.ExecuteNonQuery()
End Sub

Private Sub btnsimpan_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnsimpan.Click
simpan()
daftar()
bersih()
MsgBox("Data Sudah Disimpan", MsgBoxStyle.Information, "Perhatian")
End Sub

Private Sub btnbaru_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnbaru.Click
bersih()
MsgBox("Data Sudah digagalkan", MsgBoxStyle.Information,
"Perhatian")
End Sub

Private Sub btnclose_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnclose.Click
Me.Close()
End Sub

Private Sub btncari_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btncari.Click
cari()
End Sub

Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btndelete.Click
delete()
daftar()
MsgBox("Data Telah Terhapus", MsgBoxStyle.Information,
"Informastion")
End Sub

Private Sub btnedit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnedit.Click
edit()
daftar()
MsgBox("Data Telah Terupdate", MsgBoxStyle.Information,
"Informastion")
End Sub
End Class


















Imports System.Data
Imports System.Data.OleDb

Public Class franggota
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 franggota_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'PERINTAH KONEKSI DATABASE DISIMPAN 1 BARIS
koneksi = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=|DataDirectory|\dbperpustakaan.mdb"
conn = New OleDb.OleDbConnection(koneksi)
conn.Open()
End Sub
Sub bersih()
Me.txtkodeanggota.Focus()
Me.txtnama.Text = ""
Me.txtalamat.Text = ""
Me.txttelepon.Text = ""
End Sub

Sub simpan()
sql1 = "Insert into tbanggota values('" & Me.txtkodeanggota.Text &
"','" & Me.txtnama.Text & "','" & Me.txtalamat.Text & "','" &
Me.txttelepon.Text & "')"
cmd = New OleDb.OleDbCommand(sql1)
cmd.Connection = conn
cmd.ExecuteNonQuery()
End Sub

Sub daftar()
sql2 = "select * from tbanggota"
dtadapter = New OleDbDataAdapter(sql2, conn)
Dim BRG As New DataTable
BRG.Clear()
dtadapter.Fill(BRG)
DgvAnggota.DataSource = BRG
End Sub
Sub cari()
Dim cari As String
cari = InputBox("Masukan Kode Anggota", "Pencarian")
sql3 = "select * from tbanggota where Kode_Anggota = '" & cari &
"'"
dtadapter = New OleDbDataAdapter(sql3, conn)
Dim CST As New DataTable
CST.Clear()
dtadapter.Fill(CST)
DgvAnggota.DataSource = CST
End Sub
Sub delete()
Dim hapus As String
hapus = InputBox("Masukan Kode Anggota", "Penghapusan")
sql4 = "delete from tbanggota where Kode_Anggota = '" & hapus & "'"
cmd = New OleDb.OleDbCommand(sql4)
cmd.Connection = conn
cmd.ExecuteNonQuery()
End Sub
Sub edit()
sql5 = "update tbanggota set Nama = '" & txtnama.Text & "', Alamat
= '" & txtalamat.Text & "', Telepon = '" & txttelepon.Text & "' where
Kode_Anggota = '" & txtkodeanggota.Text & "'"
cmd = New OleDb.OleDbCommand(sql5)
cmd.Connection = conn
cmd.ExecuteNonQuery()
End Sub

Private Sub btnsimpan_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnsimpan.Click
simpan()
daftar()
bersih()
MsgBox("Data Sudah Disimpan", MsgBoxStyle.Information, "Perhatian")
End Sub

Private Sub btnbaru_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnbaru.Click
bersih()
MsgBox("Data Sudah digagalkan", MsgBoxStyle.Information,
"Perhatian")
End Sub

Private Sub btnclose_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnclose.Click
Me.Close()
End Sub

Private Sub btncari_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btncari.Click
cari()
End Sub

Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btndelete.Click
delete()
daftar()
MsgBox("Data Telah Terhapus", MsgBoxStyle.Information,
"Informastion")
End Sub

Private Sub btnedit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnedit.Click
edit()
daftar()
MsgBox("Data Telah Terupdate", MsgBoxStyle.Information,
"Informastion")
End Sub
End Class


















Imports System.Data
Imports System.Data.OleDb

Public Class FrTransaksi
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 rd As OleDb.OleDbDataReader
Public dtadapter As New OleDb.OleDbDataAdapter
Public dttable As New DataTable

Sub tampilan1()
cmd = New OleDbCommand("select distinct Kode_Anggota from
tbanggota", conn)
rd = cmd.ExecuteReader
Do While rd.Read
cmbkodeanggota.Items.Add(rd.Item(0))
Loop
End Sub
Sub tampilan2()
cmd = New OleDbCommand("select distinct Kode_Buku from tbbuku",
conn)
rd = cmd.ExecuteReader
Do While rd.Read
cmbkodebuku.Items.Add(rd.Item(0))
Loop
End Sub
Private Sub FrTransaksi_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'PERINTAH KONEKSI DATABASE DISIMPAN 1 BARIS
koneksi = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=|DataDirectory|\dbperpustakaan.mdb"
conn = New OleDb.OleDbConnection(koneksi)
conn.Open()
tampilan1()
tampilan2()
End Sub

Sub bersih()
Me.txtkodetransaksi.Focus()
Me.cmbkodeanggota.Text = ""
Me.cmbkodebuku.Text = ""
Me.txttanggalpinjam.Text = ""
Me.txttanggalkembali.Text = ""
End Sub

Sub simpan()
sql1 = "Insert into tbtransaksi values('" &
Me.txtkodetransaksi.Text & "','" & Me.cmbkodeanggota.Text & "','" &
Me.cmbkodebuku.Text & "','" & Me.txttanggalpinjam.Text & "','" &
Me.txttanggalkembali.Text & "')"
cmd = New OleDb.OleDbCommand(sql1)
cmd.Connection = conn
cmd.ExecuteNonQuery()
End Sub

Sub daftar()
sql2 = "select * from tbtransaksi"
dtadapter = New OleDbDataAdapter(sql2, conn)
Dim BRG As New DataTable
BRG.Clear()
dtadapter.Fill(BRG)
DgvTransaksi.DataSource = BRG
End Sub
Sub cari()
Dim cari As String
cari = InputBox("Masukan Kode Transaksi", "Pencarian")
sql3 = "select * from tbtransaksi where Kode_Transaksi = '" & cari
& "'"
dtadapter = New OleDbDataAdapter(sql3, conn)
Dim CST As New DataTable
CST.Clear()
dtadapter.Fill(CST)
DgvTransaksi.DataSource = CST
End Sub
Sub delete()
Dim hapus As String
hapus = InputBox("Masukan Kode Transaksi", "Penghapusan")
sql4 = "delete from tbtransaksi where Kode_Transaksi = '" & hapus &
"'"
cmd = New OleDb.OleDbCommand(sql4)
cmd.Connection = conn
cmd.ExecuteNonQuery()
End Sub
Sub edit()
sql5 = "update tbtransaksi set Kode_Anggota = '" &
cmbkodeanggota.Text & "', Kode_Buku = '" & cmbkodebuku.Text & "',
Tanggal_Pinjam = '" & txttanggalpinjam.Text & "' , Tanggal_Kembali = '" &
txttanggalkembali.Text & "' where Kode_Transaksi = '" &
txtkodetransaksi.Text & "'"
cmd = New OleDb.OleDbCommand(sql5)
cmd.Connection = conn
cmd.ExecuteNonQuery()
End Sub

Private Sub btnsimpan_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnsimpan.Click
simpan()
daftar()
bersih()
MsgBox("Data Sudah Disimpan", MsgBoxStyle.Information, "Perhatian")
End Sub

Private Sub btnbaru_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnbaru.Click
bersih()
MsgBox("Data Sudah digagalkan", MsgBoxStyle.Information,
"Perhatian")
End Sub

Private Sub btnclose_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnclose.Click
Me.Close()
End Sub

Private Sub btncari_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btncari.Click
cari()
End Sub

Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btndelete.Click
delete()
daftar()
MsgBox("Data Telah Terhapus", MsgBoxStyle.Information,
"Informastion")
End Sub

Private Sub btnedit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnedit.Click
edit()
daftar()
MsgBox("Data Telah Terupdate", MsgBoxStyle.Information,
"Informastion")
End Sub
End Class