0

I am trying to delete a record from a table by using dao recordset. Currently I am working with the code listed below. Unfortunately i've realised that this code only deletes the first record in my table, whereas I am looking to delete a record form the table with an ID that I would have put in textbox1

 Private Sub btnDelete_Click(sender As System.Object, e As System.EventArgs) Handles btnDelete.Click


        Dim AccessEngine As New DBEngine

       Dim db As Database = AccessEngine.OpenDatabase(DatabasePath)
        Dim dbs As Microsoft.Office.Interop.Access.Dao.Recordset = db.OpenRecordset("myTable",     RecordsetTypeEnum.dbOpenDynaset)

        dbs.Delete()
        End Sub

Edited by pyTony: clean code tagging

2
Contributors
5
Replies
6
Views
4 Years
Discussion Span
Last Post by Reverend Jim
0
Dim con As New ADODB.Connection
    con.Open("Driver={Microsoft Access Driver (*.mdb)};Dbq=d:\temp\mydb.mdb;Uid=username;Pwd=password;")
    con.Execute("delete from myTable where ID=" & txtID.Text)
    con.Close()

That's if ID is numeric. If it is a string then use

con.Execute("delete from myTable where ID='" & txtID.Text & "'")

Edited by pyTony: clean code tagging

0

thanks Reverend-Jim but I am using DAO recordsetswith interop is there anyway to go about such operations while avoiding SQL strings

0

I'm really not up on DAO but you could always put the "delete record by ID" into a custom method using ADO and "black box" the code.

0

thanx but I didnt get the part where you said "black box the code" what do you mean

0

Code the "delete record with this ID" as a method that contains all of the messy ADO details. The remainder of your program doesn't have to know how the function/method does its work. Thus "black box". When you find a better way just replace the innards.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.