06-Removing Year Level

This tutorial is all about Removing Year Level.
Today, I’m going to remove whatever wrong records that have been saved in Ms Access Database. Deleting records in a system is not advisable but when you’re developing a system you will have to undergo many testing to make the system more accurate.

 

 

Let’s begin:

 

 

Open the project that I have created last time which is “StudentInformation” and do the Form just like this.
removingyl_form1
After setting up the Form, Double click the “Delete” Button to fire the event handler of it and add this following code for deleting the records in Ms Access Database.
[vbnet]
Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
Try
‘opening the connection
con.Open()
‘store a query to a variable that you have declared.
query = “DELETE * FROM tbllevel WHERE LEVELID =” & dtgyllist.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(“Year Level has been removed.”)
txtyl.Clear()
levelid = 0
Catch ex As Exception
‘catching error
MsgBox(ex.Message)
End Try
con.Close()
End Sub
[/vbnet]
Now, press F5 on the keyboard to run the project and click a record in the DataGridView that you’re going to remove and hit the “Delete” Button to fire the Code in the method.

 

 

Readers might read also:

 

 

Leave a Comment