11-Retrieving User

0
375

This tutorial is all about Retrieving User.
In this tutorial, I will teach you how to retrieve the user’s records in the MySQL Database. with this, the records will be displayed in the DataGridView and I’m going to change some of the properties in the DataGridView to make it suitable.

 

 

Let’s begin:

 

 

Open the file of “EmployeesInformationSystem” and go to the “ManageUserForm“. In the “ManageUserForm“, drag a DataGridView and name it “dgtList“.

userregformretrieveform_0

After dragging a DataGridView, double click the Form to fire the Load event of it. In the ManageUserForm_Load, add the following code for setting up the properties of the DataGridView and retrieving the data in the MySQL Database. The records that you have saved in the database will automatically display in the DataGridView on the first load of the Form.

[vbnet] ‘SETTING UP THE PROPERTIES OF A DATAGRIDVIEW
With dtgList
‘IT DISABLED THE ADD ROWS FUNCTION
.AllowUserToAddRows = False
‘IT DISABLE THE EDIT FUNCTION
.EditMode = DataGridViewEditMode.EditProgrammatically
‘IT ADJUSTTHE COLUMNS DEPENDS ON HOW LONG THE TEXT INSIDE OF IT
.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
‘IT ADJUST THE ROWS DEPENDS ON HOW LONG THE TEXT INSIDE IT
.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
End With

‘STORE A SLECT QUERY IN A STRING VARIABLE
query = “SELECT USER_ID, UNAME, USERNAME, TYPE FROM useraccounts
‘SET A RETRIEVE METHOD THAT YOU HAD CREATED.
mysqlRetrieve(query, dtgList)
[/vbnet]

Go back to the Form Design and double click the Button to fire the click event handler of it. In the btnSave_Click, set a query and put it into the method for retrieving the data in the MySQL Database that you had created. Then put it under the insert function to refresh the list of records in the DatagridView after saving the data.

[vbnet] ‘STORE A SLECT QUERY IN A STRING VARIABLE
query = “SELECT USER_ID, UNAME, USERNAME, TYPE FROM useraccounts
‘SET A RETRIEVE METHOD THAT YOU HAD CREATED.
mysqlRetrieve(query, dtgList)
[/vbnet]

This will be the appearance of the full codes in the “code view” that you have created.

[vbnet] Public Class ManageUserForm
Private Sub ManageUserForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
‘MAKING THE TEXT INTO DOTS IN THE PASSWORD TEXTBOX
txtPassword.UseSystemPasswordChar = True
‘ADD ITEM IN THE COMBOBOX
With cboType.Items
.Add(“Administrator”)
.Add(“Staff”)
.Add(“Encoder”)
End With

‘SETTING UP THE PROPERTIES OF A DATAGRIDVIEW
With dtgList
‘IT DISABLED THE ADD ROWS FUNCTION
.AllowUserToAddRows = False
‘IT DISABLE THE EDIT FUNCTION
.EditMode = DataGridViewEditMode.EditProgrammatically
‘IT ADJUSTTHE COLUMNS DEPENDS ON HOW LONG THE TEXT INSIDE OF IT
.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
‘IT ADJUST THE ROWS DEPENDS ON HOW LONG THE TEXT INSIDE IT
.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
End With

‘STORE A SLECT QUERY IN A STRING VARIABLE
query = “SELECT USER_ID, UNAME, USERNAME, TYPE FROM useraccounts
‘SET A RETRIEVE METHOD THAT YOU HAD CREATED.
mysqlRetrieve(query, dtgList)
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
query = “insert into useraccounts (USER_ID, UNAME, USERNAME, PASS, TYPE)” & _
“values (‘” & txtUserId.Text & “‘,'” & txtName.Text & “‘,'” & txtUsername.Text & _
“‘,'” & txtPassword.Text & “‘,'” & cboType.Text & “‘)”
mysqlCreate(query)

‘STORE A SLECT QUERY IN A STRING VARIABLE
query = “SELECT USER_ID, UNAME, USERNAME, TYPE FROM useraccounts
‘SET A RETRIEVE METHOD THAT YOU HAD CREATED.
mysqlRetrieve(query, dtgList)
End Sub
End Class
[/vbnet]

 

Readers might read also:

12-Searching Users

13-Updating Users

 

 

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.