Imports
System.Data.OleDb
Public Class Form1
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:\vb2\siswa.mdb"
db = New
OleDbConnection(LOKASI)
If
db.State = ConnectionState.Closed Then
db.Open()
End If
End Sub
Sub
tampilrecordsiswa()
adp = New
OleDbDataAdapter("select*from siswa",
db)
ds = New
DataSet
adp.Fill(ds, "siswa")
DataGridView1.DataSource = ds.Tables("siswa")
End Sub
Sub
buttonbaru()
BtnBaru.Enabled = True
BtnSimpan.Enabled = False
BtnEdit.Enabled = False
BtnHapus.Enabled = False
BtnBatal.Enabled = False
BtnKeluar.Enabled = True
End Sub
Sub
buttonedit()
BtnBaru.Enabled = False
BtnSimpan.Enabled = False
BtnEdit.Enabled = True
BtnHapus.Enabled = True
BtnBatal.Enabled = True
BtnKeluar.Enabled = False
End Sub
Sub
buttonsimpan()
BtnBaru.Enabled = False
BtnSimpan.Enabled = True
BtnEdit.Enabled = False
BtnHapus.Enabled = False
BtnBatal.Enabled = True
BtnKeluar.Enabled = False
End Sub
Sub
hapustext()
NIS.Text = ""
NamaLengkap.Text = ""
JenisKelamin.Text = ""
TTL.Text = ""
Agama.Text = ""
AnakKe.Text = ""
JSaudara.Text = ""
Status.Text = ""
AlmtSiswa.Text = ""
TlpnSiswa.Text = ""
AsalSekolah.Text = ""
NamaAyah.Text = ""
NamaIbu.Text = ""
KerjaAyah.Text = ""
KerjaIbu.Text = ""
AlmtOrtu.Text = ""
TlpnOrtu.Text = ""
End Sub
Private Sub BtnHapus_Click(ByVal
sender As System.Object, ByVal e As System.EventArgs)
Handles BtnHapus.Click
Sql = "DELETE
FROM SISWA where NIS='" & NIS.Text & "'"
cmd = New
OleDbCommand(Sql, db)
cmd.ExecuteNonQuery()
Call
BtnBaru_Click(sender, e)
Call
tampilrecordsiswa()
End Sub
Private Sub BtnKeluar_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles BtnKeluar.Click
Me.Close()
End Sub
Private Sub Form1_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call
opendb()
Call
hapustext()
Call
tampilrecordsiswa()
JenisKelamin.Items.Add("Laki-Laki")
JenisKelamin.Items.Add("Perempuan")
Agama.Items.Add("Kristen Katolik")
Agama.Items.Add("Kristen Protestan")
Agama.Items.Add("Islam")
Agama.Items.Add("Hindu")
Agama.Items.Add("Budha")
Agama.Items.Add("Dan Lain-Lain")
AnakKe.Items.Add("1")
AnakKe.Items.Add("2")
AnakKe.Items.Add("3")
AnakKe.Items.Add("4")
AnakKe.Items.Add("5")
AnakKe.Items.Add("6")
AnakKe.Items.Add("7")
AnakKe.Items.Add("8")
AnakKe.Items.Add("9")
AnakKe.Items.Add("10")
AnakKe.Items.Add("Diatas 10")
JSaudara.Items.Add("0")
JSaudara.Items.Add("1")
JSaudara.Items.Add("1")
JSaudara.Items.Add("2")
JSaudara.Items.Add("3")
JSaudara.Items.Add("4")
JSaudara.Items.Add("5")
JSaudara.Items.Add("6")
JSaudara.Items.Add("7")
JSaudara.Items.Add("8")
JSaudara.Items.Add("9")
JSaudara.Items.Add("10")
JSaudara.Items.Add("Diatas 10")
Status.Items.Add("Anak Kandung")
Status.Items.Add("Anak Angkat")
End Sub
Private Sub BtnBaru_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles BtnBaru.Click
Call
hapustext()
NIS.Focus()
End Sub
Private Sub NIS_KeyPress(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles
NIS.KeyPress
Dim
tombol As Integer
= Asc(e.KeyChar)
Dim
xkode As String
If
tombol = 13 Then
Sql = "select*
from siswa where NIS='" & NIS.Text & "'"
cmd = New
OleDbCommand(Sql, db)
dr = cmd.ExecuteReader
dr.Read()
If
dr.HasRows = True Then
NamaLengkap.Text = dr.Item(2)
JenisKelamin.Text = dr.Item(3)
TTL.Text = dr.Item(4)
Agama.Text = dr.Item(5)
AnakKe.Text = dr.Item(6)
JSaudara.Text = dr.Item(7)
Status.Text = dr.Item(8)
AlmtSiswa.Text = dr.Item(9)
TlpnSiswa.Text = dr.Item(10)
AsalSekolah.Text = dr.Item(11)
NamaAyah.Text = dr.Item(12)
NamaIbu.Text = dr.Item(13)
KerjaAyah.Text = dr.Item(14)
KerjaIbu.Text = dr.Item(15)
AlmtOrtu.Text = dr.Item(16)
TlpnOrtu.Text = dr.Item(17)
Call
buttonedit()
MsgBox("DATA
DITEMUKAN !")
Else
xkode = NIS.Text
Call
hapustext()
NIS.Text = xkode
Call
buttonsimpan()
End
If
NamaLengkap.Focus()
End If
End Sub
Private Sub BtnEdit_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles BtnEdit.Click
Sql = "UPDATE
SISWA SET NamaLengkap='" & NamaLengkap.Text & "'," & _
" JenisKelamin='" &
JenisKelamin.Text & "'," &
_
" TTL='" & TTL.Text & "'," & _
" Agama='" & Agama.Text & "'," & _
" AnakKe='" & AnakKe.Text & "'," & _
" JSaudara='" & JSaudara.Text & "'," & _
" Status='" & Status.Text & "'," & _
" AlmtSiswa='" & AlmtSiswa.Text
& "'," & _
" Tlpnsiswa='" & TlpnSiswa.Text
& "'," & _
" Asalsekolah='" & AsalSekolah.Text
& "'," & _
" NamaAyah='" & NamaAyah.Text & "'," & _
" NamaIbu='" & NamaIbu.Text & "'," & _
"
kerjaAyah='" & KerjaAyah.Text & "',"
& _
" kerjaIbu='" & KerjaIbu.Text & "'," & _
" AlmtOrtu='" & AlmtOrtu.Text & "'," & _
" TlpnOrtu='" & TlpnOrtu.Text & "' " & _
" where NIS='" & NIS.Text & "'"
cmd = New
OleDbCommand(Sql, db)
cmd.ExecuteNonQuery()
Call
BtnBaru_Click(sender, e)
Call
tampilrecordsiswa()
End Sub
Private Sub BtnSimpan_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles BtnSimpan.Click
Sql = "INSERT
INTO SISWA(NIS, NamaLengkap, JenisKelamin, TTL, Agama, AnakKe, JSaudara,
Status, AlmtSiswa, TlpnSiswa, AsalSekolah, NamaAyah, NamaIbu, KerjaAyah,
KerjaIbu, AlmtOrtu, TlpnOrtu) " & _
"
values('" & NIS.Text & "','"
& _
NamaLengkap.Text
& "','" & _
JenisKelamin.Text
& "','" & _
TTL.Text & "','" & _
Agama.Text & "','" & _
AnakKe.Text &
"','" & _
JSaudara.Text
& "','" & _
Status.Text &
"','" & _
AlmtSiswa.Text
& "','" & _
TlpnSiswa.Text
& "','" & _
AsalSekolah.Text
& "','" & _
NamaAyah.Text
& "','" & _
NamaAyah.Text & "','"
& _
KerjaAyah.Text
& "','" & _
KerjaIbu.Text
& "','" & _
AlmtOrtu.Text
& "','" & _
TlpnOrtu.Text
& "')"
cmd = New
OleDbCommand(Sql, db)
cmd.ExecuteNonQuery()
Call
BtnBaru_Click(sender, e)
Call
tampilrecordsiswa()
End Sub
Private Sub BtnBatal_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles BtnBatal.Click
Call
hapustext()
NIS.Focus()
End Sub
End Class
Tidak ada komentar:
Posting Komentar