0% found this document useful (0 votes)
16 views5 pages

Mysqlconnection Form1 Object Eventargs

This document contains code for a Visual Basic application that manages customer data in a MySQL database. It includes functions for loading the form, displaying customers, clearing fields, generating new customer IDs, validating and saving new customer data, updating and deleting existing customer records, and handling clicks on the data grid view.

Uploaded by

Dedy Azwar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views5 pages

Mysqlconnection Form1 Object Eventargs

This document contains code for a Visual Basic application that manages customer data in a MySQL database. It includes functions for loading the form, displaying customers, clearing fields, generating new customer IDs, validating and saving new customer data, updating and deleting existing customer records, and handling clicks on the data grid view.

Uploaded by

Dedy Azwar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 5

Imports MySql.Data.

MySqlClient
Imports MySql.Data
Imports MySql.Data.MySqlClient.MySqlConnection
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
bukaDB()
tampilPelanggan()
aturTampilan()
segarkan()
End Sub
Sub segarkan()
txtIDPelanggan.Text = ""
txtAlamatPelanggan.Text = ""
txtNamaPelanggan.Text = ""
txtNoTelp.Text = ""
txtIDPelanggan.Focus()
txtIDPelanggan.Enabled = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles cmdBaru.Click
'membuat kode pelanggan baru dengan menggunakan kombinasi
'awalan PEL dengan tanggal dan tahun serta dengan jam menit dan detik pada waktu
dicreate txtIDPelanggan.Text = "PEL" & DateTime.Now.ToString("ddyy") &
DateTime.Now.ToString("HHmms
s") End Sub
Private Sub cmdSimpan_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSimpan.Click
'membuat validasi input
If txtIDPelanggan.Text = "" Then
MsgBox("Klik tombol id baru untuk membuat kode pelanggan", vbExclamation,
"Pemograman Visual I")
cmdBaru.Focus(
) Exit Sub
ElseIf txtNamaPelanggan.Text = "" Then
MsgBox("Kolom nama pelanggan harus diisi", vbExclamation, "Pemograman Visual
txtNamaPelanggan.Focus(
I")
) Exit Sub
ElseIf txtAlamatPelanggan.Text = "" Then
MsgBox("Kolom alamat pelanggan harus diisi", vbExclamation, "Pemograman
Visual I")
txtAlamatPelanggan.Focus()
Exit Sub
ElseIf txtNoTelp.Text = "" Then
MsgBox("kolom no telp pelanggan harus diisi", vbExclamation, "Pemograman
Visual I")
txtNoTelp.Focus()
Else Dim sqlSimpan As String = "INSERT INTO
user(idPelanggan,namaPelanggan,alamatPelanggan,noTelpPelanggan)" & _
"VALUES('" & txtIDPelanggan.Text & "','" & txtNamaPelanggan.Text & "','"
& txtAlamatPelanggan.Text & "', " & _
"'" & txtNoTelp.Text & "')"

Try With sqlCommand


.CommandText = sqlSimpan
.Connection = sqlConnection
.
ExecuteNonQuery()
tampilPelanggan()
aturTampilan()
segarkan()
MsgBox("Data Pelanggan Berhasil Disimpan", vbInformation, "Pemograman
Visual I")

End With
Catch
ex
As
Exc
ept
ion
Ms
gB
ox(
ex.
Me
ssa
ge)
sql
Co
m
ma
nd.
Dis
pos
e()
Tut
up
DB
()
End Try
End If
End Sub
Private Sub txtNoTelp_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles txtNoTelp.KeyPress
If Not (e.KeyChar >= "0" And e.KeyChar <= "9" Or
e.KeyChar = vbBack) Then e.Handled = True
End If
End Sub
Sub
a
t
u
r
T
a
m
p
il
a
n
(
)
T
r
y

W
th
D
at
a
G
id
V
e
w
1
.
C
ns
W
=
.
C
ns
H
rT
=
Pe
ga
.
C
ns
W
=
.
C
ns
H
rT
=
"N
Pe
ga
.
C
ns
W
=
.
C
ns
H
rT
=
"A
at
Pe
ga
.
C
ns
W
=

)
cmdHapus_Click(ByVal sender As System.Object, ByVal e As
x System.EventArgs) Handles cmdHapus.Click
T
txtIDPel
W
anggan
C
.Text =
e
""
E
txtNoTe
io
lp.Text
= ""
E
T
E
d
S
b
S
b
t
m
p
P
la
n
g
n
)
T
b
D
A
M
A
E
F
u
k
D
N
D
m
)
D
e
o
C
e
E
io

C
lu
m
ns
(3

P
v
t
S
b

s
e
s
E
T
E
d
S
b

txtNamaPelanggan.Text = ""
txtAlamatPelanggan.Text = ""
txtIDPelanggan.Focus()
End Sub
Sub IsiTeks(ByVal x As Integer)
Try
txtIDPelanggan.Text = DataGridView1.Rows(x).Cells(0).Value
txtNamaPelanggan.Text = DataGridView1.Rows(x).Cells(1).Value
txtAlamatPelanggan.Text = DataGridView1.Rows(x).Cells(2).Value
txtNoTelp.Text = DataGridView1.Rows(x).Cells(3).Value
Catch ex As Exception
End Try
End Sub
Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
IsiTeks(e.RowIndex)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button2.Click
Dim pesan As Integer
pesan = MsgBox("Apakah anda yakin ingin menghapus data dengan ID Pelanggan : " &
txtIDPelanggan.Text & " ?", vbQuestion + vbYesNo, "Pemograman Visual I")
If pesan = vbYes Then
Try
bukaDB()
Dim mDA As New MySqlDataAdapter("DELETE FROM user WHERE idPelanggan
= '"
& txtIDPelanggan.Text & "'", konek)
Dim dt As New DataTable
mDA.Fill(dt)
DataGridView1.Refresh()
tampilPelanggan()
aturTampilan()
MsgBox("Data Pelanggan Berhasil Dihapus", vbInformation, "TPemograman
Visual I")
Catch ex As Exception
MsgBox(ex.Messag
e) End Try
End If
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim pesan As Integer
pesan = MsgBox("Apakah anda yakin ingin meng-update data dengan ID Pelanggan : "
& txtIDPelanggan.Text & " ?", vbQuestion + vbYesNo, "Pemograman Visual I")
Try
bukaDB()
Dim mDA As New MySqlDataAdapter("UPDATE user SET namaPelanggan='" &
txtNamaPelanggan.Text & "',alamatPelanggan = '" & txtAlamatPelanggan.Text & "'," & _
"noTelpPelanggan = '" & txtNoTelp.Text & "'
WHERE idPelanggan = '" & txtIDPelanggan.Text & "'", konek)
Dim dt As New DataTable
mDA.Fill(dt)
DataGridView1.Refresh()
tampilPelanggan()
aturTampilan()

MsgBox("Data Pelanggan dengan ID : " & txtIDPelanggan.Text & " berhasil


diupdate", vbInformation, "Pemograman Visual I")
Catch ex As Exception
MsgBox(ex.Messag
e) End Try
End Sub
End Class

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy