Imports MySql.Data.MySqlClient
Public Class Form1
Dim Sql As String
Dim RS As MySqlDataReader
Dim Cmd As MySqlCommand
Dim DB As New MySql.Data.MySqlClient.MySqlConnection
Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GroupBox1.Enter
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles npm.TextChanged
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call opendb()
Call buat_table()
Call isi_tabel)
End Sub
Sub opendb()
Sql = "server=localhost;uid=root;pwd=;database=kampus"
Try
DB.ConnectionString = Sql
DB.Open()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Sub buat_table()
With LV
.Columns.Add("npm", 80, HorizontalAlignment.Left)
.Columns.Add("nm_mahasiswa", 150, HorizontalAlignment.Left)
.Columns.Add("kelas", 20, HorizontalAlignment.Left)
.Columns.Add("semester", 100, HorizontalAlignment.Left)
.Columns.Add("thn_ajaran", 100, HorizontalAlignment.Left)
.Columns.Add("matakuliah", 150, HorizontalAlignment.Left)
.GridLines = True
.FullRowSelect = True
.View = View.Details
End With
End Sub
Sub isi_tabel()
LV.Items.Clear()
Sql = "Select*From mahasiswa"
Cmd = New MySqlCommand(Sql, DB)
RS = Cmd.ExecuteReader
Try
While RS.Read
Dim list As New ListViewItem
list.Text = RS("npm")
list.SubItems.Add(RS("nm_mahasiswa"))
list.SubItems.Add(RS("kelas"))
list.SubItems.Add(RS("semester"))
list.SubItems.Add(RS("thn_ajaran"))
list.SubItems.Add(RS("matakuliah"))
LV.Items.Add(list)
End While
Catch ex As Exception
MsgBox(ex.Message)
End Try
RS.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNSIMPAN.Click
Sql = "insert into mahasiswa(npm,nm_mahasiswa,kelas,semester,thn_ajaran,matakuliah)" & _
"values(" & npm.Text & _
" ' , ' " & nama.Text & _
" ' , ' " & kelas.Text & _
" ' , ' " & semester.Text & _
" ' , ' " & ta.Text & _
" ' , ' " & mtk.Text & " ')"
Try
Cmd = New MySqlCommand(Sql, DB)
Cmd.ExecuteNonQuery()
MessageBox.Show("data telah di simpan")
Call isi_tabel()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
Tidak ada komentar:
Posting Komentar