Sie sind auf Seite 1von 3

Imports MySql.Data.

MySqlClient
Public Class Form1

Sub kosongkan_Data()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""

End Sub
Sub TextMati()
TextBox1.Enabled = False
TextBox2.Enabled = False
TextBox3.Enabled = False
End Sub
Sub TextHidup()
TextBox1.Enabled = True
TextBox2.Enabled = True
TextBox3.Enabled = True
End Sub

Sub tampilkan_Data()
da = New MySqlDataAdapter("SELECT * FROM mahasiswa ", conn)
ds = New DataSet
ds.Clear()
da.Fill(ds, "mahasiswa")
DataGridView1.DataSource = (ds.Tables("mahasiswa"))
DataGridView1.Columns(0).Width = 77
DataGridView1.Columns(1).Width = 250
End Sub

Sub TampilGrid()
Call Koneksi()
da = New MySqlDataAdapter("select * From mahasiswa ", conn)
DS = New DataSet
da.Fill(ds, "mahasiswa")
DataGridView1.DataSource = ds.Tables("mahasiswa")
DataGridView1.ReadOnly = True
End Sub

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles


MyBase.Load
Call TextMati()
Call kosongkan_Data()
Call koneksi()
Call tampilkan_Data()

End Sub

Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles

Button3.Click ===============HAPUS
If TextBox1.Text = "" Then
MsgBox("Silahkan Pilih Data yang akan di hapus dengan Masukan NIM dan ENTER")
Else
If MessageBox.Show("Yakin akan dihapus..?", "", MessageBoxButtons.YesNo) =
Windows.Forms.DialogResult.Yes Then
Call koneksi()
Dim hapus As String = "delete From mahasiswa where nim='" &
TextBox1.Text & "'"
cmd = New MySqlCommand(hapus, conn)
cmd.ExecuteNonQuery()
Call TampilGrid()
Call kosongkan_Data()
End If
End If

End Sub

Private Sub TextBox1_KeyPress(sender As Object, e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
TextBox1.MaxLength = 6
If e.KeyChar = Chr(13) Then
Call koneksi()
cmd = New MySqlCommand("Select * From mahasiswa where NIM='" & TextBox1.Text
& "'", conn)
dr = cmd.ExecuteReader
dr.Read()
If Not dr.HasRows Then
MsgBox("NIM Tidak Ada, Silahkan coba lagi!")
TextBox1.Focus()
Else
TextBox2.Text = dr.Item("nama")
TextBox3.Text = dr.Item("alamat")
TextBox2.Focus()
End If
End If

End Sub

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles


Button1.Click ==========================TAMBAH
Call TextHidup()
Call kosongkan_Data()
TextBox2.Focus()
End Sub

Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles


Button5.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
MsgBox("Silahkan Isi Semua Form")
Else
Call koneksi()
Dim simpan As String = "insert into mahasiswa values ('" & TextBox1.Text &
"','" & TextBox2.Text & "','" & TextBox3.Text & "')"
cmd = New MySqlCommand(simpan, conn)
cmd.ExecuteNonQuery()
MsgBox("Input data berhasil")
Call tampilkan_Data()
Call kosongkan_Data()
End If
End Sub

Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles


Button6.Click =================EDIT
Call koneksi()
Dim edit As String = "update mahasiswa set nama='" & TextBox2.Text & "',alamat='"
& TextBox3.Text & "' where nim='" & TextBox1.Text & "'"
cmd = New MySqlCommand(edit, conn)
cmd.ExecuteNonQuery()
MsgBox("Data Berhasil diUpdate")
Call TampilGrid()
Call kosongkan_Data()

End Sub

Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles


Button4.Click ========================TUTUP
Me.Close()
End Sub
End Class

Das könnte Ihnen auch gefallen