Minggu, 08 Juni 2014

Membuat Program Aplikasi Siswa Menggunakan Database Access untuk Menyimpan Data Siswa

Assalamu'alaikum..

Sudah lama juga jari-jari saya tidak mencet-mencet tombol keyboard heheh...
Hai Guys kali ini saya aka memostingkan Membuat Program Aplikasi Siswa Menggunakan Database Access untuk Menyimpan Data Siswa ... Nah kali ini jika karakter diinputkan maka akan bisa disimpan dilistview,.. Nah berikut ini adalah tampilan dari  Program Aplikasi Siswa Menggunakan Database Access untuk Menyimpan Data Siswa..

1. Pertama kita munculkan dulu Form Menu utamanya,,  


listing Programnya:

Public Class Form2


    Private Sub SiswaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SiswaToolStripMenuItem.Click
        Form1.Show()
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub
End Class


2. Kemudian setelah diklik menu siswa maka akan muncul: 

Listing Programnya:

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=h:\Melda ulansari\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 BtnBaru()
        btn_baru.Enabled = True
        btn_simpan.Enabled = False
        btn_edit.Enabled = False
        btn_hapus.Enabled = False
        btn_batal.Enabled = False
        btn_keluar.Enabled = True
    End Sub
    Sub BtnEdit()
        btn_baru.Enabled = False
        btn_simpan.Enabled = False
        btn_edit.Enabled = True
        btn_hapus.Enabled = True
        btn_batal.Enabled = True
        btn_keluar.Enabled = False
    End Sub
    Sub BtnSimpan()
        btn_baru.Enabled = False
        btn_simpan.Enabled = True
        btn_edit.Enabled = False
        btn_hapus.Enabled = False
        btn_batal.Enabled = True
        btn_keluar.Enabled = False
    End Sub
    Sub HapusText()
        nis.Text = ""
        Nama_siswa.Text = ""
        alamat.Text = ""
        nama_wali.Text = ""
        tgl_lahir.Text = ""
        agama.Text = ""
        jenis_kelamin.Text = ""
        Call ButtonBaru()
    End Sub

    Sub Recordsiswa()
        ADP = New OleDbDataAdapter("SELECT * FROM siswa", DB)
        DS = New DataSet
        ADP.Fill(DS, "siswa")
        DataGridView1.DataSource = DS.Tables("siswa")
    End Sub
    Sub ButtonBaru()
        btn_baru.Enabled = True
        btn_simpan.Enabled = False
        btn_edit.Enabled = False
        btn_hapus.Enabled = False
        btn_batal.Enabled = False
        btn_keluar.Enabled = True
    End Sub
    Sub BunttonEdit()
        btn_baru.Enabled = False
        btn_simpan.Enabled = False
        btn_edit.Enabled = True
        btn_hapus.Enabled = True
        btn_batal.Enabled = True
        btn_keluar.Enabled = False
    End Sub
    Sub ButtonSimpan()
        btn_baru.Enabled = False
        btn_simpan.Enabled = True
        btn_edit.Enabled = False
        btn_hapus.Enabled = False
        btn_batal.Enabled = True
        btn_keluar.Enabled = False
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call openDB()
        Call HapusText()
        Call Recordsiswa()
        agama.Items.Add("Islam")
        agama.Items.Add("Kristen")
        agama.Items.Add("Hindu")
        agama.Items.Add("Budha")
        jenis_kelamin.Items.Add("Laki-Laki")
        jenis_kelamin.Items.Add("Perempuan")
    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
                Nama_siswa.Text = DR("Nama_siswa")
                alamat.Text = DR("alamat")
                nama_wali.Text = DR("nama_wali")
                tgl_lahir.Text = DR("tgl_lahir")
                agama.Text = DR("agama")
                jenis_kelamin.Text = DR("jenis_kelamin")
                Call BunttonEdit()
                MsgBox("Data Ditemukan !!!!!! ")

            Else
                xkode = NIS.Text
                Call HapusText()
                NIS.Text = xkode
                Call ButtonSimpan()
            End If
            DR.Close()
            Nama_siswa.Focus()
        End If
    End Sub

    Private Sub btn_baru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_baru.Click
        Call HapusText()
        NIS.Focus()
    End Sub

    Private Sub btn_simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_simpan.Click
        SQL = "insert into siswa (nis,nama_siswa,alamat,nama_wali,tgl_lahir,agama,jenis_kelamin)" & _
      "values ('" & NIS.Text & "','" & _
      Nama_siswa.Text & "','" & _
      alamat.Text & "','" & _
      nama_wali.Text & "','" & _
      tgl_lahir.Text & "','" & _
      agama.Text & "','" & _
      jenis_kelamin.Text & "')"


        CMD = New OleDbCommand(SQL, DB)
        CMD.ExecuteNonQuery()
        Call btn_baru_Click(sender, e)
        Call Recordsiswa()
    End Sub

    Private Sub btn_edit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_edit.Click
        SQL = "UPDATE siswa SET nama_siswa='" & Nama_siswa.Text & "', " & _
                     " alamat='" & alamat.Text & "', " & _
                     " nama_wali='" & nama_wali.Text & "', " & _
                     " tgl_lahir='" & tgl_lahir.Text & "', " & _
                     " jenis_kelamin='" & jenis_kelamin.Text & "' " & _
                     " Where nis='" & NIS.Text & "'"

        CMD = New OleDbCommand(SQL, DB)
        CMD.ExecuteNonQuery()
        Call btn_baru_Click(sender, e)
        Call Recordsiswa()
    End Sub

    Private Sub btn_hapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_hapus.Click
        SQL = "DELETE FROM siswa Where NIS='" & NIS.Text & "'"
        CMD = New OleDbCommand(SQL, DB)
        CMD.ExecuteNonQuery()
        Call btn_baru_Click(sender, e)
        Call Recordsiswa()
    End Sub

    Private Sub btn_batal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_batal.Click
        Call HapusText()
        NIS.Focus()
    End Sub

    Private Sub btn_keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_keluar.Click
        Me.Close()
    End Sub
End Class


3. Berikut ini tampilan databasenya:


Demikianlah artikeldari saya yang berjudul Membuat Program Aplikasi Siswa Menggunakan Database Access untuk Menyimpan Data Siswa Semoga bermanfaat bagi taman taman semua..........

Wassalamu'alaikum....

Tidak ada komentar:

Posting Komentar