06-Search Employees

0
366

This tutorial is all about Search Employees.

In this tutorial, I will teach you how to search the record of the Employee in the database. With this, you can search the record that depends on the category that you’re going to choose.

 

So, lets begin:

 

Open the file “EmployeesInformationSystem” that you have created. After that, drag a GroupBox. In the GroupBox, drag a TextBox and a ComboBox. Name the TextBox “txtseach” and the ComboBox “cboCategory”. Chang the text of the GroupBox which is “Search” and it will look like this.
employeesregformretrivedata2form
After setting up the GroupBox, double click the Form and add the items in the ComboBox on the first load of the Form.

  1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2. 'ADDING ITEMS IN THE COMBOBOX
  3. With cboCategory
  4. .Items.Add("ID")
  5. .Items.Add("NAME")
  6. End With
  7. End Sub

After adding the items in the ComboBox, go back to the Form Design and double click the TextBox in the GroupBox to fire the TextChanged event handler of it. After that, you have to condition if what are the categories that you’re going to used in searching the records in the DataGridView.

  1. Private Sub txtsearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.TextChanged
  2. Try
  3. 'CHECKING IF WHAT CATEGORY THAT YOUR GOING THE SEARCH
  4. If cboCategory.Text = "ID" Then
  5. 'THIS IS FOR THE ID OF THE EMPLOYEE
  6. query = "SELECT E.`EMPLOYEE_ID`, concat(`LAST_NAME`,', ',`FIRST_NAME`,' ', `MIDDLE_NAME`) as NAME" & _
  7. ", `ADDRESS`, `GENDER`, `AGE`,`D_HIRED` AS HIRED_DATE,`D_RATE` AS DAILY_RATE,`W_STATUS` AS STATUS " & _
  8. " FROM `employees` as E, `employeesworkinfo` W WHERE E.`EMPLOYEE_ID`=W.`EMPLOYEE_ID` " & _
  9. "AND E.`EMPLOYEE_ID` LIKE '%" & txtsearch.Text & "%'"
  10. mysqlRetrieve(query, DataGridView1)
  11. ElseIf cboCategory.Text = "NAME" Then
  12. 'AND THIS IS FOR THE FULL NAME OF THE EMPLOYEE
  13. query = "SELECT E.`EMPLOYEE_ID`, concat(`LAST_NAME`,', ',`FIRST_NAME`,' ', `MIDDLE_NAME`) as NAME" & _
  14. ", `ADDRESS`, `GENDER`, `AGE`,`D_HIRED` AS HIRED_DATE,`D_RATE` AS DAILY_RATE,`W_STATUS` AS STATUS " & _
  15. " FROM `employees` as E, `employeesworkinfo` W WHERE E.`EMPLOYEE_ID`=W.`EMPLOYEE_ID` " & _
  16. "AND concat(`LAST_NAME`,', ',`FIRST_NAME`,' ', `MIDDLE_NAME`) LIKE '%" & txtsearch.Text & "%'"
  17. mysqlRetrieve(query, DataGridView1)
  18. End If
  19. Catch ex As Exception
  20. MsgBox(ex.Message)
  21. End Try
  22. End Sub

 

Readers might read also:

 

 

Facebook Comments
(Visited 50 times, 1 visits today)

LEAVE A REPLY

Please enter your comment!
Please enter your name here