Senin, 09 Januari 2012

Button Hapus

Koneksi.Open()
Try
Cari = InputBox("Masukkan NPM yang mau dihapus")
SQLCommand.Connection = Koneksi
SQLCommand.CommandType = CommandType.Text
SQLCommand.CommandText = "DELETE * From TUAS WHERE Kd_Matkul='" & Cari & "'"
SQLCommand.ExecuteNonQuery()
MsgBox("Sukses Terhapus", MsgBoxStyle.OkOnly, "Hapus")

Catch ex As Exception
MsgBox("NPM yang anda masukkan tidak terdaftar", MsgBoxStyle.OkOnly, "Hapus")
End Try
Koneksi.Close()
tampilList()
End Sub
Sub tampilList()
Try
No = 1
ListView1.Items.Clear()
Koneksi.Close()
Koneksi.Open()
SQLCommand.Connection = Koneksi
SQLCommand.CommandType = CommandType.Text
SQLCommand.CommandText = "SELECT * From TUAS Order By Kd_Matkul "
SBaca = SQLCommand.ExecuteReader
While SBaca.Read
Dim IsiGrid As ListViewItem
IsiGrid = ListView1.Items.Add(No)
IsiGrid.SubItems.Add(SBaca("Kd_Matkul")).ToString()
IsiGrid.SubItems.Add(SBaca("Nm_Matkul")).ToString()
IsiGrid.SubItems.Add(SBaca("Smstr")).ToString()
IsiGrid.SubItems.Add(SBaca("SKS")).ToString()
No += 1
End While
Koneksi.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try

Tidak ada komentar: