The following Microsoft Visual Basic sample code demonstrates this behavior:
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
cn.Open "Provider=MSDASQL.1;DSN=YourDSN;UID=YourUserId;PWD=YourPassword;"
On Error Resume Next
cn.Execute "drop table RSDelete"
On Error GoTo 0
cn.Execute "CREATE TABLE RSDelete (ID int NOT NULL IDENTITY (1, 1), TextField char(10) NOT NULL, OtherField char(10) )"
rs.Open "SELECT * FROM RSDelete", cn, adOpenDynamic, adLockPessimistic
rs.AddNew
rs("TextField") = "Value1"
rs("OtherField") = "Dummy A"
rs.Update
rs.AddNew
rs("TextField") = "Value1"
rs("OtherField") = "Dummy B"
rs.Update
rs.AddNew
rs("TextField") = "Value2"
rs("OtherField") = "Dummy C"
rs.Update
rs.AddNew
rs("TextField") = "Value2"
rs("OtherField") = "Dummy D"
rs.Update
rs.Close
Debug.Print "Before delete"
Debug.Print "============="
Call show_rows(rs, cn)
rs.Open "SELECT TextField FROM RSDelete where ID = 1", cn, adOpenStatic, adLockPessimistic
rs.MoveFirst
rs.Delete
rs.Close
Debug.Print "After delete"
Debug.Print "============"
Call show_rows(rs, cn)
cn.Close
End Sub
Private Sub show_rows(rs As ADODB.Recordset, cn As ADODB.Connection)
rs.Open "SELECT * FROM RSDelete", cn, adOpenStatic, adLockPessimistic
Do While Not rs.EOF
For i = 0 To rs.Fields.Count - 1
Debug.Print rs(i)
Next
Debug.Print " "
rs.MoveNext
Loop
rs.Close
End Sub
If you capture an ODBC Trace while the above code is running, you can see the following DELETE statement:
"DELETE FROM RSDelete WHERE (TextField=?)"
If you modify the query in the above code as follows:
rs.Open "SELECT * FROM RSDelete where ID = 1", cn, adOpenStatic, adLockPessimistic
rs.MoveFirst
rs.Delete
rs.Close
you will see the following DELETE statement in the ODBC Trace:
"DELETE FROM RSDelete WHERE (ID=? AND TextField=? AND OtherField=?)"
In the latter case, the parameters are bound to the respective columns in each row.