Senin, 09 Januari 2012

Button Simpan

Koneksi.Close()
Try
Koneksi.Open()
SQLCommand.Connection = Koneksi
SQLCommand.CommandType = CommandType.Text
SQLCommand.CommandText = "INSERT INTO TUAS Values ('" & TextBox1.Text & "', " & _
" '" & TextBox2.Text & "', " & _
" '" & TextBox3.Text & "', " & _
" '" & TextBox4.Text & "')"
SQLCommand.ExecuteNonQuery()
MsgBox("Sukses Tersimpan", MsgBoxStyle.OkOnly, "Sukses")
Catch ex As Exception
MsgBox("Npm Yang telah anda masukan telah ada")
End Try
Koneksi.Close()
tampilList()

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

Button Cari

button cari
Cari = InputBox("Masukkan NPM ")
Koneksi.Close()
Koneksi.Open()
SQLCommand.Connection = Koneksi
SQLCommand.CommandType = CommandType.Text
SQLCommand.CommandText = "SELECT * FROM TUAS where NPM ='" & Cari & "'"
SBaca = SQLCommand.ExecuteReader
SBaca.Read()
If SBaca.HasRows = True Then
MessageBox.Show("Data Ada ")
TextBox1.Text = Cari
TextBox2.Text = SBaca("Nm_Matkul")
TextBox3.Text = SBaca("Smstr")
TextBox4.Text = SBaca("SKS")
Else
MessageBox.Show("Data Tidak Ada ")
End If

Koneksi.Close()