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
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 & "'")

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

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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.