107 – MySQL Insert, Update, Delete Statement for Managing Payroll System Module

0
268

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.

  1. Dim result As Integer

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.

  1. Public Function saveInsert(ByVal sql As String) As Boolean
  2.  
  3. Try
  4. con.Open()
  5. With cmd
  6. .Connection = con
  7. .CommandText = sql
  8.  
  9. result = cmd.ExecuteNonQuery
  10. If result = 0 Then
  11. Return False
  12. Else
  13. Return True
  14. End If
  15. End With
  16. Catch ex As Exception
  17. MsgBox(ex.Message, MsgBoxStyle.Information)
  18. Finally
  19. con.Close()
  20.  
  21. End Try
  22.  
  23. End Function

This function is for our insert statement. And we will be defining the statement later in our button event.

  1. Public Function saveUpdate(ByVal sql As String) As Boolean
  2. Try
  3. con.Open()
  4. With cmd
  5. .Connection = con
  6. .CommandText = sql
  7. result = cmd.ExecuteNonQuery
  8. If result = 0 Then
  9.  
  10. Return False
  11. Else
  12. Return True
  13.  
  14. End If
  15. End With
  16. Catch ex As Exception
  17. MsgBox(ex.Message, MsgBoxStyle.Information)
  18. Finally
  19. con.Close()
  20.  
  21. End Try
  22.  
  23. End Function

This function is for our update statement. And we will be defining the statement later in our button event.

  1. Public Function ejbDelete(ByVal sql As String) As Boolean
  2. Try
  3. con.Open()
  4. With cmd
  5. .Connection = con
  6. .CommandText = sql
  7. result = cmd.ExecuteNonQuery
  8. If result = 0 Then
  9. Return False
  10. Else
  11. Return True
  12. End If
  13. End With
  14. Catch ex As Exception
  15. MsgBox(ex.Message, MsgBoxStyle.Information)
  16. Finally
  17. con.Close()
  18.  
  19. End Try
  20.  
  21. End Function

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.

Facebook Comments
(Visited 283 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here