PENDATAAN PELAKU MENGGUNAKAN VB.NET SYARAT UNTUK BISA MENNGIKUTI UJIAN MESRAN.NET
Langkah
pertama buat lah database menggunakan
microsoft office acceses
seperti gambar d atas kemudian kemudian simpan lah di local
C dengan folder baru dengan nama vb3 setelah itu desain lah from seperti gambar d bawah ini
menggunakan Microsoft visual studio 2008
Setelah
itu listing program di bawah ini
Imports System.Data.OleDb
Public Class PELAKU
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:\vb3\Database2.mdb"
DB = New OleDbConnection(LOKASI)
If DB.State = ConnectionState.Closed Then
DB.Open()
End If
End Sub
Sub TampilRecordPELAKU()
ADP = New OleDbDataAdapter("SELECT * FROM PELAKU", DB)
DS = New DataSet
ADP.Fill(DS, "PELAKU")
DataGridView1.DataSource = DS.Tables("PELAKU")
End Sub
Sub BARU()
Button1.Enabled = True
Button2.Enabled = False
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = False
Button6.Enabled = True
End Sub
Sub simpan()
Button1.Enabled = False
Button2.Enabled = True
Button3.Enabled = False
Button4.Enabled = False
Button5.Enabled = True
Button6.Enabled = False
End Sub
Sub EDIT()
Button1.Enabled = False
Button2.Enabled = False
Button3.Enabled = True
Button4.Enabled = True
Button5.Enabled = True
Button6.Enabled = False
End Sub
Sub HapusText()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
Call BARU()
End Sub
Private Sub
Button4_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
Button4.Click
SQL = "DELETE *FROM PELAKU Where
NIK='" & TextBox1.Text & "'"
CMD = New OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call Button1_Click(sender, e)
Call TampilRecordPELAKU()
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 PELAKU(NIK, Nama,
JEN_KELAMIN, ALAMAT, PEKERJAAN, AGAMA, SUKU, KEWARGAAN) " & _
" values('" &
TextBox1.Text & "','" & _
TextBox2.Text &
"','" & _
ComboBox1.Text &
"','" & _
TextBox3.Text &
"','" & _
TextBox4.Text &
"','" & _
TextBox5.Text &
"','" & _
TextBox6.Text &
"','" & _
TextBox7.Text &
"')"
CMD = New OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call Button1_Click(sender, e)
Call TampilRecordPELAKU()
End Sub
Private Sub
Button3_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
Button3.Click
SQL = "UPDATE PELAKU SET NAMA='"
& TextBox2.Text & "',"
& _
"JEN_KELAMIN='" & ComboBox1.Text
& "'," & _
"ALAMAT='" & TextBox3.Text & "'," & _
"PEKERJAAN='" & TextBox4.Text & "'," & _
"AGAMA='" & TextBox5.Text & "'," & _
"SUKU='" & TextBox6.Text & "'," & _
"KEWARGAAN='" & TextBox7.Text & "' " & _
"Where NIK='" & TextBox1.Text & "'"
CMD = New OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call Button1_Click(sender, e)
Call TampilRecordPELAKU()
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
PELAKU_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
MyBase.Load
Call Opendb()
Call HapusText()
Call TampilRecordPELAKU()
ComboBox1.Text = "JENIS KELAMIN"
ComboBox1.Items.Add("LAKI-LAKI")
ComboBox1.Items.Add("PEREMPUAN")
ComboBox1.Items.Add("WARIA")
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 PELAKU where
NIK='" & TextBox1.Text & "'"
CMD = New OleDbCommand(SQL, DB)
DR = CMD.ExecuteReader
DR.Read()
If DR.HasRows = True
Then
TextBox2.Text = DR.Item(2)
TextBox3.Text = DR.Item(4)
TextBox4.Text = DR.Item(5)
TextBox5.Text = DR.Item(6)
TextBox7.Text = DR.Item(7)
Call EDIT()
MsgBox("berhasil...berhasil...berhasil...Data
ditemukan...! ")
Else
xkode = TextBox1.Text
Call HapusText()
TextBox1.Text = xkode
Call simpan()
End If
TextBox2.Focus()
End If
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
selamat mencoba d rumah buat kawan-kawan sekian dan terima kasih,,,,