ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

08-Retrieve and Update Academic Year

This time, I’m going to retrieve and update all the Academic Year in Ms Access Database and there are some changes to the design of the Form.

 

 

Let’s begin:

 

 

Open the project which is “StudentInformation“. After that, add two Buttons and DataGridView inside the GroupBox in the Form. It will look like this.
retrieveupdatesy_form1

Now, double click the “Load” Button inside the academic year GroupBox and do this method for retrieving the academic year in Ms Access Database that will display in the DatagridView.

  1. Private Sub dtnsyload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtnsyload.Click
  2. Try
  3. 'opening the connection
  4. con.Open()
  5. 'store a query to a variable that you have declared.
  6. query = "SELECT * FROM tblsy"
  7. 'set a query and a connection string to a class that you have declared.
  8. da = New OleDb.OleDbDataAdapter(query, con)
  9. dt = New DataTable
  10. 'Filling the data in the datatable
  11. da.Fill(dt)
  12. 'Get or set the datasource of a datagridview to display the data that came from the database.
  13. dtgsylist.DataSource = dt
  14.  
  15. Catch ex As Exception
  16. 'catching error
  17. MsgBox(ex.Message)
  18. End Try
  19. con.Close()
  20. End Sub

After that, go back to the Form Design and click the DataGridView. After clicking it, go to the properties, click the event that looks like a lightning and scroll down to find the “DoubleClick” event handler.
retrieveupdatesy_form2

In the event handler of the DataGridView, do this following code for passing the data from a DataGridView to the TextBox.

  1. Dim syid As Integer = 0
  2. Private Sub dtgsylist_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtgsylist.DoubleClick
  3. Try
  4. 'passing the value to a variable
  5. syid = dtgsylist.CurrentRow.Cells(0).Value
  6. 'passing the value to a textbox
  7. txtyl.Text = dtgsylist.CurrentRow.Cells(1).Value
  8. Catch ex As Exception
  9. 'catching error
  10. MsgBox(ex.Message)
  11. End Try
  12. End Sub

And Lastly, these are the codes for updating the “Academic Year” in Ms Access Database.

  1. Private Sub btnsyupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsyupdate.Click
  2. Try
  3. 'opening the connection
  4. con.Open()
  5. 'store a query to a variable that you have declared.
  6. query = "UPDATE tblsy SET SY = '" & txtyl.Text & "' WHERE SYID =" & levelid & ""
  7. 'set a query and a connection string to a class that you have declared.
  8. da = New OleDb.OleDbDataAdapter(query, con)
  9. dt = New DataTable
  10. 'Filling the data in the datatable
  11. da.Fill(dt)
  12.  
  13. MsgBox("School Year has been updated.")
  14. txtsy.Clear()
  15. syid = 0
  16. Catch ex As Exception
  17. 'catching error
  18. MsgBox(ex.Message)
  19. End Try
  20. con.Close()
  21. End Sub
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!