Imports
System.Data.OleDb
Public Class JABATAN
Public DB As OleDbConnection
Public CMD As OleDbCommand
Public ADP As OleDbDataAdapter
Public DR As OleDbDataReader
Public DS As New DataSet
Dim SQL As String
Public Sub OPENDB()
Dim
LOKASI = "Provider =
Microsoft.Jet.OLEDB.4.0;Data Source=C:\VB6\DATABASE141.mdb"
DB = New
OleDbConnection(LOKASI)
If
DB.State = ConnectionState.Closed Then
DB.Open()
End If
End Sub
Sub
RecordJABATAN()
ADP = New
OleDbDataAdapter("SELECT * FROM
KD_JABATAN", DB)
DS = New
DataSet
ADP.Fill(DS, "KD_JABATAN")
DataGridView1.DataSource = DS.Tables("KD_JABATAN")
End Sub
Sub
butoonbaru()
Button1.Enabled = True
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = False
Button6.Enabled = True
End Sub
Sub
butoonedit()
Button1.Enabled = False
Button2.Enabled = False
Button3.Enabled = True
Button4.Enabled = True
Button5.Enabled = True
Button6.Enabled = False
End Sub
Sub
butoonsimpan()
Button1.Enabled = False
Button2.Enabled = True
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = True
Button6.Enabled = False
End Sub
Sub
hapustext()
TextBox1.Text = ""
TextBox2.Text = ""
Call
butoonbaru()
End Sub
Private Sub Button4_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
SQL = "DELETE
FROM KD_JABATAN Where KD_JABATAN='" & TextBox1.Text & "'"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Button1_Click(sender, e)
Call
RecordJABATAN()
End Sub
Private Sub JABATAN_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call
OPENDB()
Call hapustext()
Call
RecordJABATAN()
End Sub
Private Sub TextBox1_KeyPress(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles
TextBox1.KeyPress
Dim
tombol As Integer
= Asc(e.KeyChar)
Dim
xkode As String
If
tombol = 13 Then
SQL = "SELECT
* FROM KD_JABATAN Where KD_JABATAN='" & TextBox1.Text & "'"
CMD = New
OleDbCommand(SQL, DB)
DR = CMD.ExecuteReader
DR.Read()
If
DR.HasRows = True Then
TextBox2.Text = DR.Item(2)
Call
butoonedit()
MsgBox("DATA
DITEMUKAN!")
Else
xkode = TextBox1.Text
Call
hapustext()
TextBox1.Text = xkode
Call
butoonsimpan()
End
If
TextBox2.Focus()
End If
End Sub
Private Sub TextBox1_TextChanged(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button3_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
SQL = "UPDATE
KD_JABATAN SET NM_JABATAN='" & TextBox2.Text & "' " & _
"Where KD_JABATAN ='" &
TextBox1.Text & "'"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Button1_Click(sender, e)
Call
RecordJABATAN()
End Sub
Private Sub Button1_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Call
hapustext()
TextBox1.Focus()
End Sub
Private Sub Button2_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
SQL = "INSERT
INTO KD_JABATAN (KD_JABATAN, NM_JABATAN)" & _
"Values ('" & TextBox1.Text & "','" & _
TextBox2.Text & "')"
CMD = New
OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call
Button1_Click(sender, e)
Call
RecordJABATAN()
End Sub
Private Sub Button5_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
Call
hapustext()
TextBox1.Focus()
End Sub
Private Sub Button6_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button6.Click
Me.Close()
End Sub
End Class
PROGRAM SETELAH DI JALAN KAN:
Tidak ada komentar:
Posting Komentar