Public Class Form1
Dim mycon As New MySqlConnection("server=localhost;user id=root;password=1234;Database=MyAkademis")
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim DataAdapter As New MySqlDataAdapter("select * from TMahasiswa", mycon)
Dim DataTable As New DataTable
DataAdapter.Fill(DataTable)
DGV1.DataSource = DataTable
End Sub
Private Sub txtcari_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtcari.KeyPress
If e.KeyChar = vbCr Then
If cmbcari.Text = "NPM" Then
Dim myadapter As New MySqlDataAdapter("select * from TMahasiswa where NPM like '%" & txtcari.Text & "%'", mycon)
Dim mydatatb1 As New DataTable
myadapter.Fill(mydatatb1)
DGV1.DataSource = mydatatb1
ElseIf cmbcari.Text = "Nama" Then
Dim myadapter As New MySqlDataAdapter("select * from TMahasiswa where NMahasiswa like '%" & txtcari.Text & "%'", mycon)
Dim mydatatb1 As New DataTable
myadapter.Fill(mydatatb1)
DGV1.DataSource = mydatatb1
ElseIf cmbcari.Text = "TglLahir" Then
Dim myadapter As New MySqlDataAdapter("select * from TMahasiswa where TglLahir like '%" & txtcari.Text & "%'", mycon)
Dim mydatatb1 As New DataTable
myadapter.Fill(mydatatb1)
DGV1.DataSource = mydatatb1
ElseIf cmbcari.Text = "JKel" Then
Dim myadapter As New MySqlDataAdapter("select * from TMahasiswa where JKel like '%" & txtcari.Text & "%'", mycon)
Dim mydatatb1 As New DataTable
myadapter.Fill(mydatatb1)
DGV1.DataSource = mydatatb1
ElseIf cmbcari.Text = "Alamat" Then
Dim myadapter As New MySqlDataAdapter("select * from TMahasiswa where Alamat like '%" & txtcari.Text & "%'", mycon)
Dim mydatatb1 As New DataTable
myadapter.Fill(mydatatb1)
DGV1.DataSource = mydatatb1
End If
End If
End Sub
Sub tampil()
Dim DataAdapter As New MySqlDataAdapter("select * from TMahasiswa", mycon)
Dim DataTable As New DataTable
DataAdapter.Fill(DataTable)
DGV1.DataSource = DataTable
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
FMahasiswa2.ShowDialog()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FUbah.txtnpm1.Enabled = False
FUbah.txtnpm1.Text = DGV1.SelectedCells(0).Value
FUbah.txtnama1.Text = DGV1.SelectedCells(1).Value
FUbah.dtp2.Text = DGV1.SelectedCells(2).Value
FUbah.txtalamat1.Text = DGV1.SelectedCells(3).Value
If DGV1.SelectedCells(4).Value = "Laki-Laki" Then
FUbah.rbtJkel.Checked = True
Else
FUbah.rbtPerempuan.Checked = True
End If
FUbah.ShowDialog()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If MsgBox("Yakin mau Keluar", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Konfirmasi") = MsgBoxResult.Yes Then
End
End If
End Sub
End Class
tampilan awal
asource code tambah
Imports MySql.Data.MySqlClient
Public Class Form1
Dim mycon As New MySqlConnection("server=localhost;user id=root;password=1234;Database=MyAkademis")
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim DataAdapter As New MySqlDataAdapter("select * from TMahasiswa", mycon)
Dim DataTable As New DataTable
DataAdapter.Fill(DataTable)
DGV1.DataSource = DataTable
End Sub
Private Sub txtcari_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtcari.KeyPress
If e.KeyChar = vbCr Then
If cmbcari.Text = "NPM" Then
Dim myadapter As New MySqlDataAdapter("select * from TMahasiswa where NPM like '%" & txtcari.Text & "%'", mycon)
Dim mydatatb1 As New DataTable
myadapter.Fill(mydatatb1)
DGV1.DataSource = mydatatb1
ElseIf cmbcari.Text = "Nama" Then
Dim myadapter As New MySqlDataAdapter("select * from TMahasiswa where NMahasiswa like '%" & txtcari.Text & "%'", mycon)
Dim mydatatb1 As New DataTable
myadapter.Fill(mydatatb1)
DGV1.DataSource = mydatatb1
ElseIf cmbcari.Text = "TglLahir" Then
Dim myadapter As New MySqlDataAdapter("select * from TMahasiswa where TglLahir like '%" & txtcari.Text & "%'", mycon)
Dim mydatatb1 As New DataTable
myadapter.Fill(mydatatb1)
DGV1.DataSource = mydatatb1
ElseIf cmbcari.Text = "JKel" Then
Dim myadapter As New MySqlDataAdapter("select * from TMahasiswa where JKel like '%" & txtcari.Text & "%'", mycon)
Dim mydatatb1 As New DataTable
myadapter.Fill(mydatatb1)
DGV1.DataSource = mydatatb1
ElseIf cmbcari.Text = "Alamat" Then
Dim myadapter As New MySqlDataAdapter("select * from TMahasiswa where Alamat like '%" & txtcari.Text & "%'", mycon)
Dim mydatatb1 As New DataTable
myadapter.Fill(mydatatb1)
DGV1.DataSource = mydatatb1
End If
End If
End Sub
Sub tampil()
Dim DataAdapter As New MySqlDataAdapter("select * from TMahasiswa", mycon)
Dim DataTable As New DataTable
DataAdapter.Fill(DataTable)
DGV1.DataSource = DataTable
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
FMahasiswa2.ShowDialog()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FUbah.txtnpm1.Enabled = False
FUbah.txtnpm1.Text = DGV1.SelectedCells(0).Value
FUbah.txtnama1.Text = DGV1.SelectedCells(1).Value
FUbah.dtp2.Text = DGV1.SelectedCells(2).Value
FUbah.txtalamat1.Text = DGV1.SelectedCells(3).Value
If DGV1.SelectedCells(4).Value = "Laki-Laki" Then
FUbah.rbtJkel.Checked = True
Else
FUbah.rbtPerempuan.Checked = True
End If
FUbah.ShowDialog()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If MsgBox("Yakin mau Keluar", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Konfirmasi") = MsgBoxResult.Yes Then
End
End If
End Sub
End Class
source code ubah
Imports MySql.Data.MySqlClient
Public Class Form1
Dim mycon As New MySqlConnection("server=localhost;user id=root;password=1234;Database=MyAkademis")
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim DataAdapter As New MySqlDataAdapter("select * from TMahasiswa", mycon)
Dim DataTable As New DataTable
DataAdapter.Fill(DataTable)
DGV1.DataSource = DataTable
End Sub
Private Sub txtcari_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtcari.KeyPress
If e.KeyChar = vbCr Then
If cmbcari.Text = "NPM" Then
Dim myadapter As New MySqlDataAdapter("select * from TMahasiswa where NPM like '%" & txtcari.Text & "%'", mycon)
Dim mydatatb1 As New DataTable
myadapter.Fill(mydatatb1)
DGV1.DataSource = mydatatb1
ElseIf cmbcari.Text = "Nama" Then
Dim myadapter As New MySqlDataAdapter("select * from TMahasiswa where NMahasiswa like '%" & txtcari.Text & "%'", mycon)
Dim mydatatb1 As New DataTable
myadapter.Fill(mydatatb1)
DGV1.DataSource = mydatatb1
ElseIf cmbcari.Text = "TglLahir" Then
Dim myadapter As New MySqlDataAdapter("select * from TMahasiswa where TglLahir like '%" & txtcari.Text & "%'", mycon)
Dim mydatatb1 As New DataTable
myadapter.Fill(mydatatb1)
DGV1.DataSource = mydatatb1
ElseIf cmbcari.Text = "JKel" Then
Dim myadapter As New MySqlDataAdapter("select * from TMahasiswa where JKel like '%" & txtcari.Text & "%'", mycon)
Dim mydatatb1 As New DataTable
myadapter.Fill(mydatatb1)
DGV1.DataSource = mydatatb1
ElseIf cmbcari.Text = "Alamat" Then
Dim myadapter As New MySqlDataAdapter("select * from TMahasiswa where Alamat like '%" & txtcari.Text & "%'", mycon)
Dim mydatatb1 As New DataTable
myadapter.Fill(mydatatb1)
DGV1.DataSource = mydatatb1
End If
End If
End Sub
Sub tampil()
Dim DataAdapter As New MySqlDataAdapter("select * from TMahasiswa", mycon)
Dim DataTable As New DataTable
DataAdapter.Fill(DataTable)
DGV1.DataSource = DataTable
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
FMahasiswa2.ShowDialog()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FUbah.txtnpm1.Enabled = False
FUbah.txtnpm1.Text = DGV1.SelectedCells(0).Value
FUbah.txtnama1.Text = DGV1.SelectedCells(1).Value
FUbah.dtp2.Text = DGV1.SelectedCells(2).Value
FUbah.txtalamat1.Text = DGV1.SelectedCells(3).Value
If DGV1.SelectedCells(4).Value = "Laki-Laki" Then
FUbah.rbtJkel.Checked = True
Else
FUbah.rbtPerempuan.Checked = True
End If
FUbah.ShowDialog()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If MsgBox("Yakin mau Keluar", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Konfirmasi") = MsgBoxResult.Yes Then
End
End If
End Sub
End Class
Tidak ada komentar:
Posting Komentar