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.
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.
TabControl1_Selected, you have to set a code for setting up the properties and display the records in the DataGridView.
- 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.<code>EMPLOYEE_ID</code>, concat(<code>LAST_NAME</code>,', ',<code>FIRST_NAME</code>,' ', <code>MIDDLE_NAME</code>) as NAME" & _
- ", <code>ADDRESS</code>, <code>GENDER</code>, <code>AGE</code>,<code>D_HIRED</code> AS HIRED_DATE,<code>D_RATE</code> AS DAILY_RATE,<code>W_STATUS</code> AS STATUS " & _
- " FROM <code>employees</code> 'CALL THE METHOD THAT YOU HAVE CREATED FOR RETRIEVING DATA IN THE DATABASE
- mysqlRetrieve(query, DataGridView1)
- End Sub
Readers might read also: