Berikut adalah source code untuk button save,update, dan delete :
Sub simpan()
Try
Call Koneksi()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = " insert into ms_pegawai values('" & idpegawai.Text & "','" & nama.Text & "','" & ttl.Text & "','" & ComboBox1.Text & "','" & alamat.Text & "','" & notelp.Text & "','" & pangkat.Text & "','" & jabatan.Text & "','" & perguruan.Text & "','" & username.Text & "','" & password.Text & "','" & ComboBox2.Text & "','" & tanggal.Text & "')"
Tampilkan = Tampil.ExecuteReader
If Tampilkan.HasRows = False Then
MsgBox("data telah di simpan", vbInformation, "messange")
Call pegawai()
Call clear()
DataGridView1.Refresh()
Call atur()
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
--------------------------------------------------------------------------------------------------------------------------
Sub ubah()
Try
Call Koneksi()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "Insert ms_pegawai set id_pegawai = '" & idpegawai.Text & "',nama_pegawai = '" & nama.Text & "',ttl_pegawai = '" & ttl.Text & "',jenis_kelamin = '" & ComboBox1.Text & "',alamat_pegawai = '" & alamat.Text & "',no_telp_hp = '" & notelp.Text & "',pangkat_pegawai = '" & pangkat.Text & "',jabatan_pegawai = '" & jabatan.Text & "',perguruan_tinggi = '" & perguruan.Text & "',username = '" & username.Text & "',password = '" & password.Text & "',keterangan = '" & ComboBox2.Text & "' on duplicate key Update id_pegawai = '" & idpegawai.Text & "',nama_pegawai = '" & nama.Text & "',ttl_pegawai = '" & ttl.Text & "',jenis_kelamin = '" & ComboBox1.Text & "',alamat_pegawai = '" & alamat.Text & "',no_telp_hp = '" & notelp.Text & "',pangkat_pegawai = '" & pangkat.Text & "',jabatan_pegawai = '" & jabatan.Text & "',perguruan_tinggi = '" & perguruan.Text & "',username = '" & username.Text & "',password = '" & password.Text & "',keterangan = '" & ComboBox2.Text & "' "
Tampil.ExecuteNonQuery()
MsgBox("Data Sudah Di Ubah", vbInformation, "Message")
DataGridView1.Refresh()
Call atur()
Call clear()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
--------------------------------------------------------------------------------------------------------------------------
Sub hapus()
Dim hapus As String
hapus = MessageBox.Show("Anda yakin ingin menghapus data ini ?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If hapus = MsgBoxResult.Yes Then
Try
Call Koneksi()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = " Delete from ms_pegawai where id_pegawai = '" & idpegawai.Text & "'"
Tampil.ExecuteNonQuery()
Call atur()
MsgBox("Data Sudah Di Hapus", vbInformation, "Message")
Call clear()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
Else
End If
End Sub
