Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports MySql.Data.MySqlClient
- Public Class Frmlistpendaftar
- Private dataTable As DataTable
- Private connString As String
- Private Sub BtnKeluar_Click(sender As Object, e As EventArgs) Handles BtnKeluar.Click
- Application.Exit()
- End Sub
- Private Sub Frmlistpendaftar_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- connString = "Server=localhost;Database=pendaftaran_online;User Id=root;"
- Using conn As New MySqlConnection(connString)
- Try
- conn.Open()
- Dim query As String = "SELECT * FROM user"
- Dim adapter As New MySqlDataAdapter(query, conn)
- dataTable = New DataTable()
- adapter.Fill(dataTable)
- tableUser.DataSource = dataTable
- Catch ex As MySqlException
- MessageBox.Show("Terjadi kesalahan: " & ex.Message)
- Finally
- ' Menutup koneksi
- conn.Close()
- Console.WriteLine("Koneksi ditutup.")
- End Try
- End Using
- End Sub
- Private Sub ComboJurusan_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboJurusan.SelectedIndexChanged
- Dim selectedJurusan As String = ComboJurusan.SelectedItem.ToString()
- Dim foundRows As DataRow() = dataTable.Select("nama = '" & selectedJurusan & "'")
- If foundRows.Length > 0 Then
- ' Mengakses nilai 'ukt' dari baris yang ditemukan
- Dim ukt As Long = Convert.ToInt64(foundRows(0)("ukt"))
- Dim formattedUkt As String = ukt.ToString("N0")
- labelUkt.Text = "Rp. " + formattedUkt
- Else
- MessageBox.Show("Data UKT tidak ditemukan untuk jurusan yang dipilih.")
- End If
- ' Menampilkan semua data selain jurusan yang dipilih dalam DataGridView
- Dim filteredRows As DataRow() = dataTable.Select("nama <> '" & selectedJurusan & "'")
- dataGridUkt.Visible = True
- labelUktLain.Visible = True
- If filteredRows.Length > 0 Then
- Dim filteredDataTable As New DataTable()
- filteredDataTable = filteredRows.CopyToDataTable()
- dataGridUkt.DataSource = filteredDataTable
- dataGridUkt.Columns("ukt").DefaultCellStyle.Format = "N0"
- ' Mengganti nilai kolom 'id' dengan nomor urut
- Dim rowIndex As Integer = 1
- For Each row As DataRow In filteredDataTable.Rows
- row("id") = rowIndex
- rowIndex += 1
- Next
- Else
- dataGridUkt.DataSource = Nothing
- MessageBox.Show("Tidak ada data lain untuk ditampilkan.")
- End If
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement