0% found this document useful (0 votes)
29 views

Hapus Database MySQL VB 2010

This VB.NET code connects to a MySQL database to perform CRUD operations on a member/user table. It opens a connection to the database, displays existing members in a datagrid, allows adding/editing members by populating textboxes from a selected member, and deletes a member by their ID number by executing a DELETE query after user confirmation. The code handles validation, updating the UI, and closing the database connection.

Uploaded by

Egi Ginanjar
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)
29 views

Hapus Database MySQL VB 2010

This VB.NET code connects to a MySQL database to perform CRUD operations on a member/user table. It opens a connection to the database, displays existing members in a datagrid, allows adding/editing members by populating textboxes from a selected member, and deletes a member by their ID number by executing a DELETE query after user confirmation. The code handles validation, updating the UI, and closing the database connection.

Uploaded by

Egi Ginanjar
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
You are on page 1/ 3

Hapus Database MySQL VB 2010

Imports System.Data.Odbc
Public Class Form1
Dim Conn As OdbcConnection
Dim da As OdbcDataAdapter
Dim ds As DataSet
Dim str As String
Dim CMD As OdbcCommand
Dim RD As OdbcDataReader

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
Call KondisiAwal()
End Sub
Sub Koneksi()
str = "Driver={MySQL ODBC 5.3 ANSI
Driver};database=DBperpustakaan;server=localhost;uid=root"
Conn = New OdbcConnection(str)
If Conn.State = ConnectionState.Closed Then
Conn.Open()
End If
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or
TextBox4.Text = "" Then
MsgBox("Data belum lengkap, Pastikan Nomor anggota 6 Digit dan Semua
form terisi")
Exit Sub
Else
Call Koneksi()

If MessageBox.Show("Yakin akan dihapus..?", "",


MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then
Dim hapus As String = "DELETE FROM anggota WHERE anggota.nomoragt
= '" & TextBox1.Text & "'"
CMD = New OdbcCommand(hapus, Conn)
CMD.ExecuteNonQuery()
MsgBox("Data berhasil di Hapus", MsgBoxStyle.Information,
"Information")
Call KondisiAwal()
End If
End If
End Sub
Sub KondisiAwal()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
Koneksi()
da = New OdbcDataAdapter("Select * from anggota", Conn)
ds = New DataSet
ds.Clear()
da.Fill(ds, "anggota")
DataGridView1.DataSource = (ds.Tables("anggota"))
End Sub

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As


System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(13) Then
Call Koneksi()
CMD = New OdbcCommand("Select * from anggota where nomoragt='" &
TextBox1.Text & "'", Conn)
RD = CMD.ExecuteReader
RD.Read()

If Not RD.HasRows Then


TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox2.Focus()
Else
TextBox2.Text = RD.Item("Namaagt")
TextBox3.Text = RD.Item("alamatagt")
TextBox4.Text = RD.Item("teleponagt")
TextBox2.Focus()
End If
End If
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