09-Removing Academic Year

This tutorial is all about Removing Academic Year.
Today, I’m going to teach you how to removed the “Academic Year” in Ms Access Database using Visual Basic 2008.

 

Let’ begin:

 

Open the file which is “StudentInformation” and add a Button and place it under the DataGridView inside the “Academic Year” GroupBox in the Form. Name the Button “btnsydelete” and it will look like this.
removingsy_form1
After setting up the Form, double click the “Delete” Button and add this following code inside the “Click” event handler for removing the record in Ms Access Database.
[vbnet]
Private Sub btnsydelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsydelete.Click
Try
‘opening the connection
con.Open()
‘store a query to a variable that you have declared.
query = “DELETE * FROM tblsy WHERE SYID =” & dtgsylist.CurrentRow.Cells(0).Value & “”
‘set a query and a connection string to a class that you have declared.
da = New OleDb.OleDbDataAdapter(query, con)
dt = New DataTable
‘Filling the data in the datatable
da.Fill(dt)

MsgBox(“School Year has been removed.”)
txtyl.Clear()
levelid = 0
Catch ex As Exception
‘catching error
MsgBox(ex.Message)
End Try
con.Close()
End Sub
[/vbnet]
Finally, press F5 to run on the keyboard to run your project and click any record in the DatagridView you want to remove and hit the “Delete” Button to fire the code in the method.

 

Readers might read also:

 

 

 

Leave a Comment