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.
Open the project that I have created last time which is “StudentInformation” and do the Form just like this.
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.
- Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndelete.Click
- 'opening the connection
- '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
- MsgBox("Year Level has been removed.")
- levelid = 0
- Catch ex As Exception
- 'catching error
- End Try
- End Sub
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.