ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

08-Removing Employees

Today, I’m going to teach how to remove the Employee’s Information in the MySQL Database. With this you can remove the Information of the Employee and I’m going to add another function for clearing the fields after you add or update the Employee’s Information.

Let’s begin:

Open the file “EmployeesInformationSystem” that you had created. Drag a Button beside the “Update” Button and name it “New”. After that, drag another Button under the DataGridView in the “List of Employees” TabPage and name it “Remove“.
employeesregformdeletedataform1
employeesregformdeletedataform2
After adding Buttons, go to the Module(“dbconnection”) and create a method for clearing the text in the TextBox and RichTextBox.

  1. 'A SUB PROCEDURE FOR CLEARING ALL DATA IN THE TEXTBOX
  2. Public Sub clearingObject(ByVal obj As Object)
  3. 'FOR THE RICHTEXTBOX
  4. For Each txt As Control In obj.Controls
  5. If txt.GetType Is GetType(RichTextBox) Then
  6. txt.Text = ""
  7. End If
  8. Next
  9. 'FOR THE TEXTBOX
  10. For Each txt As Control In obj.Controls
  11. If txt.GetType Is GetType(TextBox) Then
  12. txt.Text = ""
  13. End If
  14. Next
  15. End Sub

After creating a method in the Module, go to the “Add New Employee” TabPage on the Form Design and double click the “New” Button to fire the Click event handler of it. In the btnNew_Click, call a method that you have created for clearing the text in the TextBox and RichTextBox so that, it will work when the Button is click.

  1. Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
  2. 'FOR THE PERSONAL INFORMATION GROUPBOX
  3. clearingObject(GroupBox9)
  4. 'FOR THE WORK INFORMATION GROUPBOX
  5. clearingObject(GroupBox10)
  6. 'ENABLE THE TEXTBOX ID
  7. txtempId.Enabled = True
  8. End Sub

Go back to the Form Design and click the “List of Employees” TabPage. In the “List of Employees” TabPage, double click the “Remove” Button to fire the Click event handler of it. After that, add the following code in the btnRemove_Click for removing the Employee’s records.

  1. Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
  2. 'SET A QUERY FOR DELETING THE EMPLOYEES RECORD IN THE EMPLOYEES TABLE
  3. query = "DELETE FROM `employees` WHERE `EMPLOYEE_ID`='" & DataGridView1.CurrentRow.Cells(0).Value & "'"
  4. mysqlCUDNoMessage(query)
  5. 'SET A QUERY FOR DELETING THE WORK INFORMATION RECORD OF THE EMPLOYEE IN THE EMPLOYEESWORKINFO TABLE
  6. query = "DELETE FROM `employeesworkinfo` WHERE `EMPLOYEE_ID`='" & DataGridView1.CurrentRow.Cells(0).Value & "'"
  7. mysqlDelete(query)
  8. 'TO REFRESH THE LIST OF RECORDS IN THE DATAGRIDVIEW.
  9. 'SET THIS QUERY TO RETRIEVE THE DATA IN THE DATABASE
  10. query = "SELECT E.`EMPLOYEE_ID`, concat(`LAST_NAME`,', ',`FIRST_NAME`,' ', `MIDDLE_NAME`) as NAME" & _
  11. ", `ADDRESS`, `GENDER`, `AGE`,`D_HIRED` AS HIRED_DATE,`D_RATE` AS DAILY_RATE,`W_STATUS` AS STATUS " & _
  12. " FROM `employees` as E, `employeesworkinfo` W WHERE E.`EMPLOYEE_ID`=W.`EMPLOYEE_ID`"
  13. 'CALL THE METHOD THAT YOU HAVE CREATED FOR RETRIEVING DATA IN THE DATABASE
  14. mysqlRetrieve(query, DataGridView1)
  15. End Sub
Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!