Kali ini saya akan berbagi gimana caranya membuat sebuah aplikasi Jadwal Ekskul menggunakan VS.net dan SQL Server.
1. Langkah pertama buatlah sebuah database dengan nama sesuai keinginan anda contohnya "db_ekskul" setelah itu buatlah beberapa table diantaranya (tb_guru, tb_jadwal, tb_kelas, tb_mataekskul) dengan field seperti gambar di bawah ini.
Untuk table tb_guru field nya seperti ini
Untuk table tb_jadwal field nya seperti ini
Untuk table tb_kelas field nya seperti ini
Untuk table tb_mataekskul fieldnya seperti ini
2. Langkah Ke Dua buat lah sebuah View di SQL Server anda dan jangan lupa centang Nama di table tb_guru, centang Hari di table tb_jadwal, centang Kelas dan Jurusan di table tb_kelas, centang maeks di table tb_maeks, seperti gambar di bawah ini
3. Langkah selanjutnya buka Visual Studio anda dan buat sebuah project dengan nama sesuai dengan keinginan contoh saja JadwalEskskulApps. Kemudian buatlah sebuah tampilan awal seperti gambar di bawah ini
Adapun komponen Toolbox yang di pakai yaitu terdiri dari : 2 Buah label, 5 Buah Botton
4. Langkah Selanjutnya buatlah sebuah koneksi agar VS.net & SQL server terhubung
Untuk Script Koneksi Silahkan liat di bawah ini
- Imports System.Data.SqlClient
- Module config
- Public cn As New SqlConnection
- Public cmd As New SqlCommand
- Public Sub opendb()
- cn.ConnectionString = "Data Source=STN-PC\SQLEXPRESS;Initial Catalog=db_ekskul;Integrated Security=True"
- cn.Open()
- If cn.State = ConnectionState.Open Then
- 'MessageBox.Show("DB Open")
- Else
- MessageBox.Show("DB Open Failed")
- End If
- End Sub
- End Module
5. Langkah Selanjutnya buatlah beberapa Form yaitu form guru, form kelas, form jadwal, form maeks. Untuk lebih jelasnya silahkan lihat gambar di bawah ini
Untuk tampilan Form guru
Untuk tampilan Form ekskul
Untuk tampilan Form Jadwal
6. Langkah selanjutnya ketik kan Script di bawah ini di tampilan awal yang anda buat
- Imports System.Data.SqlClient
- Public Class Home
- Sub opentable()
- cmd.Connection = cn
- cmd.CommandText = "SELECT * FROM vwjadwal"
- Dim rd As SqlDataReader = cmd.ExecuteReader
- Dim dt As New DataTable
- dt.Load(rd)
- dgvwjadwal.DataSource = dt
- End Sub
- Sub header()
- dgvwjadwal.Columns(0).HeaderText = "NAMA"
- dgvwjadwal.Columns(1).HeaderText = "HARI"
- dgvwjadwal.Columns(2).HeaderText = "KELAS"
- dgvwjadwal.Columns(3).HeaderText = "JURUSAN"
- dgvwjadwal.Columns(4).HeaderText = "MATA EKSKUL"
- End Sub
- Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
- Me.Close()
- End Sub
- Private Sub Home_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Call opendb()
- Call opentable()
- header()
- End Sub
- Private Sub dgvwjadwal_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvwjadwal.CellContentClick
- End Sub
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- frmguru.Show()
- End Sub
- Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
- frmkelas.Show()
- End Sub
- Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
- frmmaeks.Show()
- End Sub
- Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
- frmjadwal.Show()
- End Sub
- End Class
7. Langkah Selanjutnya Ketik kan script dibawah ini di Form Guru yang anda buat
- Imports System.Data.SqlClient
- Public Class frmguru
- Private Sub frmguru_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- opentable()
- End Sub
- Sub opentable()
- cmd.Connection = cn
- cmd.CommandText = "SELECT * FROM tb_guru"
- Dim rd As SqlDataReader = cmd.ExecuteReader
- Dim dt As New DataTable
- dt.Load(rd)
- dgguru.DataSource = dt
- End Sub
- Sub bersih()
- txtalamat.Text = ""
- txtkode.Text = ""
- txtnama.Text = ""
- txtnotelp.Text = ""
- End Sub
- Private Sub btnexit_Click(sender As Object, e As EventArgs) Handles btnexit.Click
- Me.Close()
- End Sub
- Private Sub btnsimpan_Click(sender As Object, e As EventArgs) Handles btnsimpan.Click
- cmd.Connection = cn
- cmd.CommandText = "insert into tb_guru values('" & txtkode.Text & "','" & txtnama.Text & "','" & txtalamat.Text & "','" &txtnotelp.Text & "')"
- cmd.ExecuteNonQuery()
- MessageBox.Show("Data Tersimpan")
- opentable()
- bersih()
- End Sub
- Private Sub btnhapus_Click(sender As Object, e As EventArgs) Handles btnhapus.Click
- Try
- cmd.CommandText = "DELETE FROM tb_guru WHERE kode_guru = '" & txtkode.Text & "'"
- cmd.ExecuteNonQuery()
- MsgBox("Data telah terhapus")
- Catch ex As Exception
- MsgBox(ex.ToString())
- End Try
- opentable()
- End Sub
- Private Sub btnubah_Click(sender As Object, e As EventArgs) Handles btnubah.Click
- Try
- cmd.CommandText = "UPDATE tb_guru SET kode_guru ='" & txtkode.Text & "', nama ='" & txtnama.Text & "', alamat = '" &txtalamat.Text & "', notelp = '" & txtnotelp.Text & "' WHERE kode_guru ='" & txtkode.Text & "'"
- cmd.ExecuteNonQuery()
- MsgBox("Data berhasil Diubah")
- Catch ex As Exception
- MsgBox(ex.ToString())
- End Try
- opentable()
- End Sub
- Private Sub dgguru_CellContentDoubleClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgguru.CellContentDoubleClick
- txtkode.Text = dgguru.SelectedCells(0).Value.ToString
- txtnama.Text = dgguru.SelectedCells(1).Value.ToString
- txtalamat.Text = dgguru.SelectedCells(2).Value.ToString
- txtnotelp.Text = dgguru.SelectedCells(3).Value.ToString
- End Sub
- Private Sub dgguru_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgguru.CellMouseDoubleClick
- txtkode.Text = dgguru.SelectedCells(0).Value.ToString
- txtnama.Text = dgguru.SelectedCells(1).Value.ToString
- txtalamat.Text = dgguru.SelectedCells(2).Value.ToString
- txtnotelp.Text = dgguru.SelectedCells(3).Value.ToString
- End Sub
- Private Sub dgguru_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgguru.CellContentClick
- End Sub
- End Class
8. Langkah selanjutnya ketik kan Script di bawah ini di Form kelas
- Imports System.Data.SqlClient
- Public Class frmkelas
- Sub opentable()
- cmd.Connection = cn
- cmd.CommandText = "SELECT * FROM tb_kelas"
- Dim rd As SqlDataReader = cmd.ExecuteReader
- Dim dt As New DataTable
- dt.Load(rd)
- dgkelas.DataSource = dt
- End Sub
- Sub bersih()
- txtjurusan.Text = ""
- txtkelas.Text = ""
- txtkode.Text = ""
- End Sub
- Private Sub frmkelas_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- opentable()
- bersih()
- End Sub
- Private Sub btnexit_Click(sender As Object, e As EventArgs) Handles btnexit.Click
- Me.Close()
- End Sub
- Private Sub btnsimpan_Click(sender As Object, e As EventArgs) Handles btnsimpan.Click
- cmd.Connection = cn
- cmd.CommandText = "insert into tb_kelas values('" & txtkode.Text & "','" & txtkelas.Text & "','" & txtjurusan.Text & "')"
- cmd.ExecuteNonQuery()
- MessageBox.Show("Data Tersimpan")
- opentable()
- bersih()
- End Sub
- Private Sub btnubah_Click(sender As Object, e As EventArgs) Handles btnubah.Click
- Try
- cmd.CommandText = "UPDATE tb_kelas SET kode_kelas ='" & txtkode.Text & "', kelas ='" & txtkelas.Text & "', jurusan = '" &txtjurusan.Text & "' WHERE kode_kelas ='" & txtkode.Text & "'"
- cmd.ExecuteNonQuery()
- MsgBox("Data berhasil Diubah")
- Catch ex As Exception
- MsgBox(ex.ToString())
- End Try
- opentable()
- End Sub
- Private Sub btnhapus_Click(sender As Object, e As EventArgs) Handles btnhapus.Click
- Try
- cmd.CommandText = "DELETE FROM tb_kelas WHERE kode_kelas = '" & txtkode.Text & "'"
- cmd.ExecuteNonQuery()
- MsgBox("Data telah terhapus")
- Catch ex As Exception
- MsgBox(ex.ToString())
- End Try
- opentable()
- End Sub
- Private Sub dgkelas_CellContentDoubleClick(sender As Object, e As DataGridViewCellEventArgs)
- txtkode.Text = dgkelas.SelectedCells(0).Value.ToString
- txtkelas.Text = dgkelas.SelectedCells(1).Value.ToString
- txtjurusan.Text = dgkelas.SelectedCells(2).Value.ToString
- opentable()
- 'bersih()
- End Sub
- Private Sub dgkelas_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs)
- txtkode.Text = dgkelas.SelectedCells(0).Value.ToString
- txtkelas.Text = dgkelas.SelectedCells(1).Value.ToString
- txtjurusan.Text = dgkelas.SelectedCells(2).Value.ToString
- opentable()
- 'bersih()
- End Sub
- End Class
9. Langkah selanjutnya Ketik kan Script di bawah ini di Form Ekskul
- Imports System.Data.SqlClient
- Public Class frmmaeks
- Sub opentable()
- cmd.Connection = cn
- cmd.CommandText = "SELECT * FROM tb_maeks"
- Dim rd As SqlDataReader = cmd.ExecuteReader
- Dim dt As New DataTable
- dt.Load(rd)
- dgmaeks.DataSource = dt
- End Sub
- Sub bersih()
- txtkode.Text = ""
- txtmaeks.Text = ""
- End Sub
- Private Sub frmmaeks_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- opentable()
- bersih()
- End Sub
- Private Sub btnexit_Click(sender As Object, e As EventArgs) Handles btnexit.Click
- Me.Close()
- End Sub
- Private Sub btnsimpan_Click(sender As Object, e As EventArgs) Handles btnsimpan.Click
- cmd.Connection = cn
- cmd.CommandText = "insert into tb_maeks values('" & txtkode.Text & "','" & txtmaeks.Text & "')"
- cmd.ExecuteNonQuery()
- MessageBox.Show("Data Tersimpan")
- opentable()
- bersih()
- End Sub
- Private Sub btnubah_Click(sender As Object, e As EventArgs) Handles btnubah.Click
- Try
- cmd.CommandText = "UPDATE tb_maeks SET kode_maeks ='" & txtkode.Text & "', maeks ='" & txtmaeks.Text & "' WHERE kode_maeks ='" &txtkode.Text & "'"
- cmd.ExecuteNonQuery()
- MsgBox("Data berhasil Diubah")
- Catch ex As Exception
- MsgBox(ex.ToString())
- End Try
- opentable()
- bersih()
- End Sub
- Private Sub btnhapus_Click(sender As Object, e As EventArgs) Handles btnhapus.Click
- Try
- cmd.CommandText = "DELETE FROM tb_maeks WHERE kode_maeks = '" & txtkode.Text & "'"
- cmd.ExecuteNonQuery()
- MsgBox("Data telah terhapus")
- Catch ex As Exception
- MsgBox(ex.ToString())
- End Try
- opentable()
- bersih()
- End Sub
- Private Sub dgmaeks_CellContentDoubleClick(sender As Object, e As DataGridViewCellEventArgs)
- txtkode.Text = dgmaeks.SelectedCells(0).Value.ToString
- txtmaeks.Text = dgmaeks.SelectedCells(1).Value.ToString
- opentable()
- End Sub
- Private Sub dgmaeks_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs)
- txtkode.Text = dgmaeks.SelectedCells(0).Value.ToString
- txtmaeks.Text = dgmaeks.SelectedCells(1).Value.ToString
- opentable()
- End Sub
- End Class
10. Langkah Selanjutnya Ketik kan script di bawah ini di Form Jadwal
- Imports System.Data.SqlClient
- Public Class frmjadwal
- Sub opentable()
- cmd.Connection = cn
- cmd.CommandText = "SELECT * FROM tb_jadwal"
- Dim rd As SqlDataReader = cmd.ExecuteReader
- Dim dt As New DataTable
- dt.Load(rd)
- dgjadwal.DataSource = dt
- End Sub
- Sub bersih()
- txthari.Text = ""
- txtkdguru.Text = ""
- txtkdjadwal.Text = ""
- txtkdkelas.Text = ""
- txtkdmaeks.Text = ""
- End Sub
- Private Sub btnexit_Click(sender As Object, e As EventArgs) Handles btnexit.Click
- Me.Close()
- End Sub
- Private Sub frmjadwal_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- opentable()
- bersih()
- End Sub
- Private Sub btnsimpan_Click(sender As Object, e As EventArgs) Handles btnsimpan.Click
- cmd.Connection = cn
- cmd.CommandText = "insert into tb_jadwal values('" & txtkdjadwal.Text & "','" & txtkdguru.Text & "','" & txtkdkelas.Text & "','" &txtkdmaeks.Text & "','" & txthari.Text & "')"
- cmd.ExecuteNonQuery()
- MessageBox.Show("Data Tersimpan")
- opentable()
- bersih()
- End Sub
- Private Sub btnubah_Click(sender As Object, e As EventArgs) Handles btnubah.Click
- Try
- cmd.CommandText = "UPDATE tb_jadwal SET kode_jadwal ='" & txtkdjadwal.Text & "', kode_guru ='" & txtkdguru.Text & "', kode_kelas = '" & txtkdkelas.Text & "', kode_maeks = '" & txtkdmaeks.Text & "', hari = '" & txthari.Text & "' WHERE kode_jadwal ='" & txtkdjadwal.Text &"'"
- cmd.ExecuteNonQuery()
- MsgBox("Data berhasil Diubah")
- Catch ex As Exception
- MsgBox(ex.ToString())
- End Try
- opentable()
- bersih()
- End Sub
- Private Sub btnhapus_Click(sender As Object, e As EventArgs) Handles btnhapus.Click
- Try
- cmd.CommandText = "DELETE FROM tb_jadwal WHERE kode_jadwal = '" & txtkdjadwal.Text & "'"
- cmd.ExecuteNonQuery()
- MsgBox("Data telah terhapus")
- Catch ex As Exception
- MsgBox(ex.ToString())
- End Try
- opentable()
- bersih()
- End Sub
- Private Sub dgjadwal_CellContentDoubleClick(sender As Object, e As DataGridViewCellEventArgs)
- txtkdjadwal.Text = dgjadwal.SelectedCells(0).Value.ToString
- txtkdguru.Text = dgjadwal.SelectedCells(1).Value.ToString
- txtkdkelas.Text = dgjadwal.SelectedCells(2).Value.ToString
- txtkdmaeks.Text = dgjadwal.SelectedCells(3).Value.ToString
- txthari.Text = dgjadwal.SelectedCells(4).Value.ToString
- opentable()
- End Sub
- Private Sub dgjadwal_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs)
- txtkdjadwal.Text = dgjadwal.SelectedCells(0).Value.ToString
- txtkdguru.Text = dgjadwal.SelectedCells(1).Value.ToString
- txtkdkelas.Text = dgjadwal.SelectedCells(2).Value.ToString
- txtkdmaeks.Text = dgjadwal.SelectedCells(3).Value.ToString
- txthari.Text = dgjadwal.SelectedCells(4).Value.ToString
- opentable()
- End Sub
- End Class
Jika Sudah selesai Silahkan Jalankan Aplikasi anda. Selamat Mengerjakan^^
wahh baguss mass tutorialnya (y)
ReplyDelete