Re: Delete a single record instead of entire recordset
- From: "Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx>
- Date: Thu, 23 Aug 2007 08:01:11 -0400
jans__@xxxxxxxxxxx wrote:
I would like to delete a single record, however the result of my
code
is that the complete recordset is deleted
Can anyone help me out here????
Here is my code
Sub DeleteAdvisor()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strSQL As String
Dim OfferDB as String
dim advisorid as string
Set cnn = New ADODB.Connection
With cnn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.Open OfferDB
End With
Set rst = New ADODB.Recordset
With rst
' Open the Recordset object.
advisorid = "12"
strSQL = "SELECT * FROM Qry_Invul_Adviseur WHERE Adviseur_id =
"
& advisorid
.Open Source:=strSQL, _
ActiveConnection:=cnn, _
CursorType:=adOpenKeyset, _
LockType:=adLockOptimistic
End With
rst.MoveFirst
rst.Delete
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
End Sub
I don't see anything here that would cause the entire recordset to be
deleted. How are you determining that this is what is happening?
However ...
You're retrieving all the fields for all the records where Adviseur_id
contains 12 just to delete a single record??? Not the most efficient
technique to be using ...
If Adviseur_id is the primary key of the source table, then there can only
be a single record in the table where Adviseur_id contains 12. So simply do
this:
strSQL = "DELETE * FROM Qry_Invul_Adviseur WHERE Adviseur_id =?"
set cmd=new adodb.command
set cmd.activeconnection=cnn
cmd.commandtype=adCmdText
cmd.Execute ,advisorid
If there could be multiple records where Adviseur_id contains 12, then post
back and let us know.
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
.
- Follow-Ups:
- Re: Delete a single record instead of entire recordset
- From: Stephen Howe
- Re: Delete a single record instead of entire recordset
- From: Bob Barrows [MVP]
- Re: Delete a single record instead of entire recordset
- References:
- Delete a single record instead of entire recordset
- From: jans__
- Delete a single record instead of entire recordset
- Prev by Date: Delete a single record instead of entire recordset
- Next by Date: Re: Delete a single record instead of entire recordset
- Previous by thread: Delete a single record instead of entire recordset
- Next by thread: Re: Delete a single record instead of entire recordset
- Index(es):
Relevant Pages
|
|