05-Retrieving Employees

This tutorial is all about Retrieving Employees.
Today, I’m going to teach you how to retrieve data in the database. Retrieving data means that, the data obtain from a database management system. In order to retrieve the data in the database that you desire, you have to present a set of criteria by a query.

So, let’s begin:

Open the file “EmployeesInformationSystem” that you had created. After that, select the TabControl as click the TabPage2, then drag a DataGridView and place it into the center of the TabPage. It will look like this.
employeesregformretrivedata
Now, select the TabControl and go to the properties. In the properties, select the events that looks like a lightning and double click the selected to fire the Selected event handler of the tabcontrol.
employeesregformretrivedataevents
In the TabControl1_Selected, you have to set a code for setting up the properties and display the records in the DataGridView.
[vbnet]
Private Sub TabControl1_Selected(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TabControlEventArgs) Handles TabControl1.Selected
With DataGridView1
‘SET THIS PROPERTIES TO DETERMINE THE COLUMN WITH AND SPECIFYING HOW ITS ADJUST
.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
‘SET THIS PROPERTIES TO DETERMINE THE HIEGHT OF THE ROWS AND SPECIFYING HOW ITS ADJUST
.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
‘SET THE FULL ROW SELECTION MODE
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
‘SET THIS PROPERTIES SO THAT YOU CAN’T ADD ROWS IN THE DATAGRIDVIEW
.AllowUserToAddRows = False
End With
‘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` ‘CALL THE METHOD THAT YOU HAVE CREATED FOR RETRIEVING DATA IN THE DATABASE
mysqlRetrieve(query, DataGridView1)
End Sub
[/vbnet]

 

Readers might read also:

 

Leave a Comment