08-Removing Employees

0
424

This tutorial is all about 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.
[vbnet] ‘A SUB PROCEDURE FOR CLEARING ALL DATA IN THE TEXTBOX
Public Sub clearingObject(ByVal obj As Object)
‘FOR THE RICHTEXTBOX
For Each txt As Control In obj.Controls
If txt.GetType Is GetType(RichTextBox) Then
txt.Text = “”
End If
Next
‘FOR THE TEXTBOX
For Each txt As Control In obj.Controls
If txt.GetType Is GetType(TextBox) Then
txt.Text = “”
End If
Next
End Sub
[/vbnet] 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.
[vbnet] Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
‘FOR THE PERSONAL INFORMATION GROUPBOX
clearingObject(GroupBox9)
‘FOR THE WORK INFORMATION GROUPBOX
clearingObject(GroupBox10)
‘ENABLE THE TEXTBOX ID
txtempId.Enabled = True
End Sub
[/vbnet] 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.
[vbnet] Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
‘SET A QUERY FOR DELETING THE EMPLOYEES RECORD IN THE EMPLOYEES TABLE
query = “DELETE FROM employees WHERE EMPLOYEE_ID='” & DataGridView1.CurrentRow.Cells(0).Value & “‘”
mysqlCUDNoMessage(query)
‘SET A QUERY FOR DELETING THE WORK INFORMATION RECORD OF THE EMPLOYEE IN THE EMPLOYEESWORKINFO TABLE
query = “DELETE FROM employeesworkinfo WHERE EMPLOYEE_ID='” & DataGridView1.CurrentRow.Cells(0).Value & “‘”
mysqlDelete(query)
‘TO REFRESH THE LIST OF RECORDS IN THE DATAGRIDVIEW.
‘SET THIS QUERY TO RETRIEVE THE DATA IN THE DATABASE
query = “SELECT E.EMPLOYEE_ID, concat(LAST_NAME,’, ‘,FIRST_NAME,’ ‘, MIDDLE_NAME) as NAME” & _
“, ADDRESS, GENDER, AGE,D_HIRED AS HIRED_DATE,D_RATE AS DAILY_RATE,W_STATUS AS STATUS ” & _
” FROM employees as E, employeesworkinfo W WHERE E.EMPLOYEE_ID=W.EMPLOYEE_ID
‘CALL THE METHOD THAT YOU HAVE CREATED FOR RETRIEVING DATA IN THE DATABASE
mysqlRetrieve(query, DataGridView1)
End Sub
[/vbnet]

 

Readers might read also:

 

 

Facebook Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.