Berikut adalah source code nya....
*note: SKMK = nama form_KeyDown
Private Sub SKMK_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.Control And e.KeyCode = Keys.P Then
Print_skmk.Show()
Me.Hide()
ElseIf e.Control And e.KeyCode = Keys.S Then
Try
Call Koneksi()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = " insert into ms_mahasiswa values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & ComboBox1.Text & "','" & TextBox4.Text & "','" & TextBox10.Text & "','" & TextBox12.Text & "','" & ComboBox2.Text & "','" & ComboBox3.Text & "','" & TextBox13.Text & "','" & TextBox17.Text & "','" & TextBox18.Text & "','" & TextBox19.Text & "','" & TextBox22.Text & "','" & TextBox23.Text & "','" & TextBox24.Text & "','" & TextBox25.Text & "','" & TextBox28.Text & "','" & TextBox30.Text & "','" & TextBox34.Text & "','" & TextBox35.Text & "','" & TextBox36.Text & "','" & TextBox37.Text & "')"
Tampilkan = Tampil.ExecuteReader
If Tampilkan.HasRows = False Then
MsgBox("data telah di simpan", vbInformation, "messange")
Call mahasiswa()
DataGridView1.Refresh()
Call atur()
End If
Catch ex As Exception
MsgBox(ex.ToString())
End Try
ElseIf e.Control And e.KeyCode = Keys.E Then
Try
Call Koneksi()
Tampil.Connection = Database
Tampil.CommandType = CommandType.Text
Tampil.CommandText = "Insert ms_mahasiswa set nim = '" & TextBox1.Text & "',nmmhsmsmhs = '" & TextBox2.Text & "',tahunmsmhs = '" & TextBox3.Text & "',nmpstmspst = '" & ComboBox1.Text & "',alamat = '" & TextBox4.Text & "',kode_p = '" & TextBox10.Text & "',phone_ot = '" & TextBox12.Text & "' ,gol_darah= '" & ComboBox2.Text & "',jenis_k= '" & ComboBox3.Text & "',agama= '" & TextBox13.Text & "',jrs_asal= '" & TextBox17.Text & "',ayah= '" & TextBox18.Text & "',ibu= '" & TextBox19.Text & "',pekerjaan_ay= '" & TextBox22.Text & "',pekerjaan_ib= '" & TextBox23.Text & "',penghasilan_ay= '" & TextBox24.Text & "',penghasilan_ib= '" & TextBox25.Text & "',nmjurmspst= '" & TextBox28.Text & "',jenjang= '" & TextBox30.Text & "',ttl= '" & TextBox34.Text & "',anak_ke= '" & TextBox35.Text & "',jml_anak= '" & TextBox36.Text & "',asal_sek= '" & TextBox37.Text & "' on duplicate key Update nim = '" & TextBox1.Text & "',nmmhsmsmhs = '" & TextBox2.Text & "',tahunmsmhs = '" & TextBox3.Text & "',nmpstmspst = '" & ComboBox1.Text & "',alamat = '" & TextBox4.Text & "',kode_p = '" & TextBox10.Text & "',phone_ot = '" & TextBox12.Text & "' ,gol_darah= '" & ComboBox2.Text & "',jenis_k= '" & ComboBox3.Text & "',agama= '" & TextBox13.Text & "',jrs_asal= '" & TextBox17.Text & "',ayah= '" & TextBox18.Text & "',ibu= '" & TextBox19.Text & "',pekerjaan_ay= '" & TextBox22.Text & "',pekerjaan_ib= '" & TextBox23.Text & "',penghasilan_ay= '" & TextBox24.Text & "',penghasilan_ib= '" & TextBox25.Text & "',nmjurmspst= '" & TextBox28.Text & "',jenjang= '" & TextBox30.Text & "',ttl= '" & TextBox34.Text & "',anak_ke= '" & TextBox35.Text & "',jml_anak= '" & TextBox36.Text & "',asal_sek= '" & TextBox37.Text & "'"
Tampil.ExecuteNonQuery()
MsgBox("Data Sudah Di Ubah", vbInformation, "Message")
DataGridView1.Refresh()
Call atur()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
ElseIf e.Control And e.KeyCode = Keys.D Then
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_mahasiswa where nim = '" & TextBox1.Text & "'"
Tampil.ExecuteNonQuery()
Call atur()
MsgBox("Data Sudah Di Hapus", vbInformation, "Message")
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End If
ElseIf e.Control And e.KeyCode = Keys.F Then
Dim nim = InputBox("Silahkan Masukan nim mahasiswa")
Try
Ds.Tables(0).PrimaryKey = New DataColumn() {Ds.Tables(0).Columns("nim")}
Dim row As DataRow
row = Ds.Tables(0).Rows.Find(nim)
TextBox1.Text = row("nim")
TextBox2.Text = row("nmmhsmsmhs")
TextBox3.Text = row("tahunmsmhs")
ComboBox1.Text = row("nmpstmspst")
TextBox4.Text = row("alamat")
TextBox10.Text = row("kode_p")
TextBox12.Text = row("phone_ot")
ComboBox2.Text = row("gol_darah")
ComboBox3.Text = row("jenis_k")
TextBox13.Text = row("agama")
TextBox17.Text = row("jrs_asal")
TextBox18.Text = row("ayah")
TextBox19.Text = row("ibu")
TextBox22.Text = row("pekerjaan_ay")
TextBox23.Text = row("pekerjaan_ib")
TextBox24.Text = row("penghasilan_ay")
TextBox25.Text = row("penghasilan_ib")
TextBox28.Text = row("nmjurmspst")
TextBox30.Text = row("jenjang")
TextBox34.Text = row("ttl")
TextBox35.Text = row("anak_ke")
TextBox36.Text = row("jml_anak")
TextBox37.Text = row("asal_sek")
MsgBox("Pencarian Sukses!")
Catch ex As Exception
MsgBox("Anda Salah Memasukkan nim / nim Tersebut Belum Terdaftar!")
End Try
ElseIf e.Control And e.KeyCode = Keys.X Then
Dim keluar As String
keluar = MessageBox.Show("Anda yakin tutup form ini ?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If keluar = MsgBoxResult.Yes Then
End
Else
End If
End If
End Sub
