ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

11-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.

  1. 'SETTING UP THE PROPERTIES OF A DATAGRIDVIEW
  2. With dtgList
  3. 'IT DISABLED THE ADD ROWS FUNCTION
  4. .AllowUserToAddRows = False
  5. 'IT DISABLE THE EDIT FUNCTION
  6. .EditMode = DataGridViewEditMode.EditProgrammatically
  7. 'IT ADJUSTTHE COLUMNS DEPENDS ON HOW LONG THE TEXT INSIDE OF IT
  8. .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
  9. 'IT ADJUST THE ROWS DEPENDS ON HOW LONG THE TEXT INSIDE IT
  10. .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
  11. End With
  12.  
  13. 'STORE A SLECT QUERY IN A STRING VARIABLE
  14. query = "SELECT `USER_ID`, `UNAME`, `USERNAME`, `TYPE` FROM `useraccounts` "
  15. 'SET A RETRIEVE METHOD THAT YOU HAD CREATED.
  16. mysqlRetrieve(query, dtgList)

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.

  1. 'STORE A SLECT QUERY IN A STRING VARIABLE
  2. query = "SELECT `USER_ID`, `UNAME`, `USERNAME`, `TYPE` FROM `useraccounts` "
  3. 'SET A RETRIEVE METHOD THAT YOU HAD CREATED.
  4. mysqlRetrieve(query, dtgList)

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

  1. Public Class ManageUserForm
  2. Private Sub ManageUserForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  3. 'MAKING THE TEXT INTO DOTS IN THE PASSWORD TEXTBOX
  4. txtPassword.UseSystemPasswordChar = True
  5. 'ADD ITEM IN THE COMBOBOX
  6. With cboType.Items
  7. .Add("Administrator")
  8. .Add("Staff")
  9. .Add("Encoder")
  10. End With
  11.  
  12. 'SETTING UP THE PROPERTIES OF A DATAGRIDVIEW
  13. With dtgList
  14. 'IT DISABLED THE ADD ROWS FUNCTION
  15. .AllowUserToAddRows = False
  16. 'IT DISABLE THE EDIT FUNCTION
  17. .EditMode = DataGridViewEditMode.EditProgrammatically
  18. 'IT ADJUSTTHE COLUMNS DEPENDS ON HOW LONG THE TEXT INSIDE OF IT
  19. .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
  20. 'IT ADJUST THE ROWS DEPENDS ON HOW LONG THE TEXT INSIDE IT
  21. .AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells
  22. End With
  23.  
  24. 'STORE A SLECT QUERY IN A STRING VARIABLE
  25. query = "SELECT `USER_ID`, `UNAME`, `USERNAME`, `TYPE` FROM `useraccounts` "
  26. 'SET A RETRIEVE METHOD THAT YOU HAD CREATED.
  27. mysqlRetrieve(query, dtgList)
  28. End Sub
  29. Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
  30. query = "insert into `useraccounts` (`USER_ID`, `UNAME`, `USERNAME`, `PASS`, `TYPE`)" & _
  31. "values ('" & txtUserId.Text & "','" & txtName.Text & "','" & txtUsername.Text & _
  32. "','" & txtPassword.Text & "','" & cboType.Text & "')"
  33. mysqlCreate(query)
  34.  
  35. 'STORE A SLECT QUERY IN A STRING VARIABLE
  36. query = "SELECT `USER_ID`, `UNAME`, `USERNAME`, `TYPE` FROM `useraccounts` "
  37. 'SET A RETRIEVE METHOD THAT YOU HAD CREATED.
  38. mysqlRetrieve(query, dtgList)
  39. End Sub
  40. End Class
Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!