1.Pertama kalian harus membuat database seperti dibawah ini :
Setelah itu tekan OK.
2.Selanjutnya kalian buat table seperti dibawah ini :
2.Selanjutnya kalian buat table seperti dibawah ini :
3.Setelah itu buat Diagram Grafik seperti dibawah ini :
4.Kemudian buat View untuk memunculkan data yg ingin dilihat contohnya seperti dibawah ini :
5.Setelah itu buka Visual Studio kalian dan buat koneksi seperti dibawah ini :
- Imports System.Data.SqlClient
- Module config
- Public cn As New SqlConnection
- Public cmd As New SqlCommand
- Public Sub opendb()
- cn.ConnectionString = "Data Source=RIZKI-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
ingat kalian harus menyesuaikan nama koneksi kalian untuk melihatnya dapat dilihat saat mau konek pada SQL Server :
6.Setelah itu buat design form utama untuk menampilkan View yg telah dibuat , untuk itu diperlukan 5 buah button dan 1 grid view , untuk label(tulisan) kalian design sesuka kalian :
Data Guru ubah name buttonnya menjadi(btnguru), Data Kelas (btnkelas), Data Ekskul (btnekskul), Jadwal(btnjadwal),Refres(btnrefresh).
7.Setelah itu klik doubel pada form yg tadi dan masukkan script dibawah ini :
- 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)
- dgvall.DataSource = dt
- End Sub
- Private Sub btnexit_Click(sender As Object, e As EventArgs) Handles btnexit.Click
- Me.Close()
- End Sub
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- opendb()
- opentable()
- End Sub
- Private Sub btnguru_Click(sender As Object, e As EventArgs) Handles btnguru.Click
- frmguru.ShowDialog()
- End Sub
- Private Sub btnkelas_Click(sender As Object, e As EventArgs) Handles btnkelas.Click
- frmkelas.ShowDialog()
- End Sub
- Private Sub btnmaeks_Click(sender As Object, e As EventArgs) Handles btnmaeks.Click
- frmmaeks.ShowDialog()
- End Sub
- Private Sub btnjadwal_Click(sender As Object, e As EventArgs) Handles btnjadwal.Click
- frmjadwal.ShowDialog()
- End Sub
- Private Sub btnrefresh_Click(sender As Object, e As EventArgs) Handles btnrefresh.Click
- opentable()
- End Sub
- End Class
8.Kemudian buat Form untuk Form Eksekusi seperti dibawah ini :
Form Guru
Form Kelas
Form Mata Ekskul
Form Jadwal
Nahh Untuk TextBox dan Buttonnya sesuaikan dengan yg digambar.
9.Setelah itu masukan script pada Form Guru seperti dibawah ini:
- 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
- End Class
10.Masukan Script ini pada 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) Handles dgkelas.CellContentDoubleClick
- txtkode.Text = dgkelas.SelectedCells(0).Value.ToString
- txtkelas.Text = dgkelas.SelectedCells(1).Value.ToString
- txtjurusan.Text = dgkelas.SelectedCells(2).Value.ToString
- opentable()
- End Sub
- Private Sub dgkelas_CellMouseDoubleClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgkelas.CellMouseDoubleClick
- txtkode.Text = dgkelas.SelectedCells(0).Value.ToString
- txtkelas.Text = dgkelas.SelectedCells(1).Value.ToString
- txtjurusan.Text = dgkelas.SelectedCells(2).Value.ToString
- opentable()
- End Sub
- End Class
11.Masukan Script ini pada Form Mata Ekskul (maeks) :
- 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) Handles dgmaeks.CellContentDoubleClick
- 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) Handles dgmaeks.CellMouseDoubleClick
- txtkode.Text = dgmaeks.SelectedCells(0).Value.ToString
- txtmaeks.Text = dgmaeks.SelectedCells(1).Value.ToString
- opentable()
- End Sub
- End Class
12.Masukan Script dibawah ini untuk 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) Handles dgjadwal.CellContentDoubleClick
- 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) Handles dgjadwal.CellMouseDoubleClick
- 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
Setelah itu Jalankan Aplikasinya dan coba isi semua form dan lihat pada form utama maka akan Data Grid View nya akan terisi.
Mudah bukan membuatnya selamat mencoba dan sampai jumpa lagi.
Mudah bukan membuatnya selamat mencoba dan sampai jumpa lagi.
Mantap
BalasHapus