0% found this document useful (0 votes)
8 views4 pages

MySQL Data Management in VB.NET Form

This document contains code for a form application that allows users to view, add, update and delete records in a student database table. It includes subroutines to retrieve student data based on an ID, clear the form fields, display all records in a datagrid, and handle button clicks for searching, inserting, updating and deleting records. The form loads with calls to initialize the database connection, display all records, and populate a gender dropdown.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

MySQL Data Management in VB.NET Form

This document contains code for a form application that allows users to view, add, update and delete records in a student database table. It includes subroutines to retrieve student data based on an ID, clear the form fields, display all records in a datagrid, and handle button clicks for searching, inserting, updating and deleting records. The form loads with calls to initialize the database connection, display all records, and populate a gender dropdown.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Imports [Link].

MySqlClient

Public Class Form1


Sub ketemu()
Dim baca As MySqlDataReader
[Link] = kOn
[Link] = "SELECT * FROM tbl_mhs where nim ='" & [Link] & "'"
baca = [Link]()
Try
While [Link]
[Link] = [Link]("nm_mhs")
[Link] = [Link]("alamat")
[Link] = [Link]("ttl")
[Link] = [Link]("jk")
End While
Catch ex As Exception
End Try
[Link]()
End Sub
Sub kosong()
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link] = ""
[Link]()
End Sub
Sub cari()
Dim dt As New DataTable
[Link] = kOn
[Link] = "SELECT * FROM tbl_mhs where Nim ='" & [Link] & "'"
baca = [Link]()
' [Link]()
End Sub
Sub TampilDb()
Dim dt As New DataTable
Try
[Link] = kOn
[Link] = "SELECT * FROM tbl_mhs "
[Link] = cmd
[Link](dt)
[Link] = dt
With Tabel
.RowHeadersVisible = False
.AllowUserToAddRows = False
.ReadOnly = True
.Refresh()
End With
Catch ex As Exception
MsgBox("Terjadi Kesalahan", vbCritical, "Error")
Exit Sub
End Try
[Link]()
End Sub

Sub combo()
[Link]("Laki-Laki")
[Link]("Perempuan")
End Sub

Private Sub Form1_Load(ByVal sender As [Link], ByVal e As [Link])


Handles [Link]
Bukadb()
TampilDb()
combo()
End Sub

Private Sub DataGridView1_CellContentClick(ByVal sender As [Link], ByVal e As


[Link])

End Sub

Private Sub Button1_Click(ByVal sender As [Link], ByVal e As [Link])


Handles [Link]
'Try
If [Link] = "" Then
MsgBox("Data Belum Lengkap")
Else
Bukadb()
Call cari()
End If
If Not [Link] Then
[Link]()
With cmd
.Connection = kOn
.CommandText = "Insert into tbl_mhs(nim,nm_mhs,alamat,ttl,jk) values " &
_
"('" & [Link] & "','" & [Link] & "','" &
[Link] & "','" & _
[Link] & "','" & [Link] & "' )"
.ExecuteNonQuery()
[Link]("Insert Data Mahasiswa Berhasil Dilakukan", "Pesan",
[Link])
kosong()
End With
Call TampilDb()

Else
[Link]()
[Link] = kOn
[Link] = "update tbl_mhs set " & _
"nm_mhs = '" & [Link] & "' ," & _
"alamat = '" & [Link] & "', " & _
"ttl = '" & [Link] & "', " & _
"jk = '" & [Link] & "' " & _
" where nim ='" & [Link] & "'"
[Link]()
[Link]("data sudah diubah", "Ubah Data",
[Link], [Link])
Call TampilDb()
kosong()
Exit Sub
End If

' Catch ex As Exception

'End Try
End Sub

Private Sub Button3_Click(ByVal sender As [Link], ByVal e As [Link])


Handles [Link]
If [Link] <> "" Then
Dim Hapus = [Link]("Yakin Data " & [Link] & "Akan Dihapus ?",
"Hapus Data", [Link], [Link])
If Hapus = [Link] Then
[Link] = kOn
[Link] = "delete from tbl_mhs where nim ='" & [Link] &
"'"
[Link]()
TampilDb()
kosong()
End If

End If
End Sub

Private Sub Button2_Click(ByVal sender As [Link], ByVal e As [Link])


Handles [Link]
kosong()
End Sub

Private Sub Button4_Click(ByVal sender As [Link], ByVal e As [Link])


Handles [Link]
[Link]()
End Sub

Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As [Link])


Handles [Link]
ketemu()
End Sub
End Class

You might also like