06-Search Employees

0
443

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.
[vbnet] Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
‘ADDING ITEMS IN THE COMBOBOX
With cboCategory
.Items.Add(“ID”)
.Items.Add(“NAME”)
End With
End Sub
[/vbnet] 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.
[vbnet] Private Sub txtsearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsearch.TextChanged
Try
‘CHECKING IF WHAT CATEGORY THAT YOUR GOING THE SEARCH
If cboCategory.Text = “ID” Then
‘THIS IS FOR THE ID OF THE EMPLOYEE
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 ” & _
“AND E.EMPLOYEE_ID LIKE ‘%” & txtsearch.Text & “%'”
mysqlRetrieve(query, DataGridView1)
ElseIf cboCategory.Text = “NAME” Then
‘AND THIS IS FOR THE FULL NAME OF THE EMPLOYEE
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 ” & _
“AND concat(LAST_NAME,’, ‘,FIRST_NAME,’ ‘, MIDDLE_NAME) LIKE ‘%” & txtsearch.Text & “%'”
mysqlRetrieve(query, DataGridView1)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
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.