Anda di halaman 1dari 4

Syntax VB Pada.

Kelompok 1

Imports System.Data.OleDb
Public Class Form1
Dim da As OleDbDataAdapter
Dim RD As OleDbDataReader
Dim ds As DataSet
Dim CMD As OleDbCommand
Dim ada1 As Boolean

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
Koneksi()
tampil()
tidakaktif()
Button1.Text = "Tambah"
tutuptombol()

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
If Button1.Text = "Tambah" Then
Call Button2_Click(sender, e)
Exit Sub
End If
If TextBox1.Text = "" Or TextBox2.Text = "" Or ComboBox1.Text = "" Then
MsgBox("Data belum lengkap, Pastikan Kode Admin 6 Digit dan Semua form
terisi")
Exit Sub
Else
If ada1 = False Then
Call Koneksi()
Dim simpan As String = "insert into t_anggota values ('" &
TextBox1.Text & "','" & TextBox2.Text & "', '" & ComboBox1.Text & "','" &
DateTimePicker1.Text & "')"
CMD = New OleDbCommand(simpan, Conn)
CMD.ExecuteNonQuery()
MsgBox("Data berhasil di Input", MsgBoxStyle.Information,
"Information")
Call tampil()
Call Button2_Click(sender, e)
End If
If ada1 = True Then
Call Koneksi()
Dim edit As String = "update t_anggota set Nama_anggota='" &
TextBox2.Text & "',Jenkel=" & ComboBox1.Text & ",tanggal_lahir=" &
DateTimePicker1.Text & "' where id_anggotag='" & TextBox1.Text & "'"
CMD = New OleDbCommand(edit, Conn)
CMD.ExecuteNonQuery()
MsgBox("Data berhasil di Edit", MsgBoxStyle.Information,
"Information")
tampil()
Call Button2_Click(sender, e)
End If
End If
End Sub
Sub tampil()
da = New OleDbDataAdapter("Select * from t_anggota", Conn)
ds = New DataSet
ds.Clear()
da.Fill(ds, "t_anggota")
DataGridView1.DataSource = (ds.Tables("t_anggota"))
DataGridView1.Columns(0).HeaderText = "id_anggota"
DataGridView1.Columns(1).HeaderText = "Nama_anggota"
DataGridView1.Columns(2).HeaderText = "Jenkel"
DataGridView1.Columns(3).HeaderText = "tanggal_lahir"
End Sub

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
CMD = New OleDbCommand("Select * from t_anggota where id_anggota='" &
TextBox1.Text & "'", Conn)
RD = CMD.ExecuteReader
RD.Read()
If Not RD.HasRows Then
tutuptombol()
ada1 = False
TextBox2.Text = ""
ComboBox1.Text = ""
DateTimePicker1.Text = ""
TextBox2.Focus()
Else
ada1 = True
bukatombol()
TextBox2.Text = RD.Item("Nama_anggota")
ComboBox1.Text = RD.Item("Jenkel")
DateTimePicker1.Text = RD.Item("tanggal_lahir")
End If
End Sub

Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As


System.EventArgs) Handles TextBox1.LostFocus
Call Koneksi()
CMD = New OleDbCommand("Select * from t_anggota where id_anggota='" &
TextBox1.Text & "'", Conn)
RD = CMD.ExecuteReader
RD.Read()
If Not RD.HasRows Then
tutuptombol()
ada1 = False
bersih()
TextBox2.Focus()
Else
bukatombol()
ada1 = True
TextBox2.Text = RD.Item("Nama_anggota")
ComboBox1.Text = RD.Item("Jenkel")
DateTimePicker1.Text = RD.Item("tanggal_lahir")
TextBox2.Focus()
End If
End Sub
Private Sub bersih()
TextBox2.Text = ""
ComboBox1.Text = ""
DateTimePicker1.Text = ""
End Sub
Private Sub tidakaktif()
TextBox2.Enabled = False
ComboBox1.Enabled = False
DateTimePicker1.Enabled = False
End Sub
Private Sub aktif()
TextBox2.Enabled = True
ComboBox1.Enabled = True
DateTimePicker1.Enabled = True
End Sub
Private Sub bukatombol()
' btnedit.Enabled = True
Button1.Enabled = True
End Sub
Private Sub tutuptombol()
' btnedit.Enabled = False
Button1.Enabled = True
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
Button1.Text = "Tambah"
bersih()
tidakaktif()
tutuptombol()
TextBox1.Enabled = True
TextBox1.Focus()
End Sub

Private Sub btnedit_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
aktif()
Button3.Enabled = False
TextBox1.Enabled = False
TextBox2.Focus()
Button1.Text = "Simpan"
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click
If MessageBox.Show("Yakin akan dihapus..?", "", MessageBoxButtons.YesNo) =
Windows.Forms.DialogResult.Yes Then
Dim hapus As String = "delete * from t_anggota where id_anggota='" &
TextBox1.Text & "'"
CMD = New OleDbCommand(hapus, Conn)
CMD.ExecuteNonQuery()
MsgBox("Data berhasil di Hapus", MsgBoxStyle.Information, "Information")
Call tampil()
Call Button2_Click(sender, e)
Exit Sub
Else
Call Button2_Click(sender, e)
Exit Sub
End If
End Sub
End Class
Syntax MOdul

Imports System.Data
Imports System.Data.Odbc
Imports System.Data.OleDb
Module Module1
Public Conn As OleDbConnection
Public LokasiDB As String
Sub Koneksi()
LokasiDB = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=E:\perpustakaan\perpus.mdb"
Conn = New OleDbConnection(LokasiDB)
If Conn.State = ConnectionState.Closed Then Conn.Open()
End Sub
End Module

Anda mungkin juga menyukai