Delete Data on MySql Database in Visual Basic Code
Author: Kevern
Date: 06/07/2011
The codes are declared on my module then being called via command button.
Option Explicit
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
'Established the database connection.
Public Sub init()
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.connectionString = ConnectionStringModule.connectionString
With conn
On Error GoTo errHandler
.Open
End With
Exit Sub
errHandler:
MsgBox Err.Description, vbCritical + vbOKOnly, "Warning"
End Sub
'Declare the delete code.
Public Sub DeleteMyData(MyData As String)
init
rs.Open "select * from DATA where DATA= '" & frmData.txtDATA& "'", conn, adOpenDynamic, adLockOptimistic
MsgBox "Primary key of the recordset to be Delete: " & frmData.txtDATA, vbInformation, "My Data"
'do delete code here
rs.Delete
rs.Close
conn.Close
End Sub
Now on your vb6 form, call the module like this:
Call ModuleName.DeleteMyData(txtDATA.text)
'Populate your flexgrid if you have one. Like update data list on the flexgrid.
Call PopulateFlexgrid.FunctionPopulate("Your Query Here",Flexgrid1)
That's All Folks...
Reach me via email if you have questions, or simply add some comments here in this blog post. I will answer all your questions anytime, even if Im too busy.
Have a Good Day!