MySQL Insert, Update, Delete Statement for Managing Payroll System Module
In our previous tutorials entitled “106 – MySQL Query Select Statement for Managing Payroll System Module“, if you are following, we started with SELECT statement in SQL which is followed by a unique set of rules and guidelines called Syntax. All the SQL statements start with any of the keywords like SELECT, MySQL INSERT, UPDATE, DELETE, ALTER, DROP, CREATE, USE, SHOW and many other.
We are going to manipulate now our data in tblEmployee. We will be inserting new employee information, we will create a module so that we can update its information and at the same time remove or delete employee information as needed.
But before we can do this, we have to modify our PayrollMod.vb module and create some function in order to define these procedures.
[vbnet]
Dim result As Integer
[/vbnet]
Add this variable declaration as Integer then add the functions below. Note that in our module function we will be coding this ones so as to make our programming life easy.
[vbnet]
Public Function saveInsert(ByVal sql As String) As Boolean
Try
con.Open()
With cmd
.Connection = con
.CommandText = sql
result = cmd.ExecuteNonQuery
If result = 0 Then
Return False
Else
Return True
End If
End With
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information)
Finally
con.Close()
End Try
End Function
[/vbnet]
This function is for our insert statement. And we will be defining the statement later in our button event.
[vbnet]
Public Function saveUpdate(ByVal sql As String) As Boolean
Try
con.Open()
With cmd
.Connection = con
.CommandText = sql
result = cmd.ExecuteNonQuery
If result = 0 Then
Return False
Else
Return True
End If
End With
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information)
Finally
con.Close()
End Try
End Function
[/vbnet]
This function is for our update statement. And we will be defining the statement later in our button event.
[vbnet]
Public Function ejbDelete(ByVal sql As String) As Boolean
Try
con.Open()
With cmd
.Connection = con
.CommandText = sql
result = cmd.ExecuteNonQuery
If result = 0 Then
Return False
Else
Return True
End If
End With
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Information)
Finally
con.Close()
End Try
End Function
[/vbnet]
This function is for our delete statement. And we will be defining the statement later in our button event. Proceed now to our next lesson to continue with our Inserting, Updating and Deleting procedures.