Click to See Complete Forum and Search --> : Deleting records in a recordset


briana02
June 15th, 2001, 12:38 PM
Hey everyone, I'm trying to delete all the records in a table using a while loop. When I executed the following code it deletes two records (out of 300) and immediately encounters EOF and exits the loop. I'm using ado...and I can't figure out why this isn't working.



set rsPic = new ADODB.Recordset
rsPic.Open "SELECT * FROM [PIC]", adCnGLC, adOpenDynamic, adLockOptimistic, _
adCmdText

If rsPic.BOF <> true then
rsPic.MoveFirst
Do While (Not rsPic.EOF)
rsPic.Delete
rsPic.MoveNext

DoEvents
Loop
End If

johnpc7
June 15th, 2001, 01:14 PM
What is the Do Events statement for?

johnpc7
June 15th, 2001, 01:14 PM
What is the Do Events statement for?

briana02
June 15th, 2001, 01:18 PM
To yield control back to VB so it can update the gui - and do whatever other processing it does.

Iouri
June 15th, 2001, 03:13 PM
WHy are you deleting in the loop? Why not to delete everything in 1 SQl
SQL = "DELETE FROM [PIC]"
Conn.Execute SQL

where Conn is your connection

Iouri Boutchkine
iouri@hotsheet.com