ADO Programming

Moderators: None (Apply to moderate this forum)
Number of threads: 87
Number of posts: 225

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Is this a BUG of M$? Posted by tony0 on 22 Sept 2005 at 10:54 PM
First,Create tst.mdb on drive D,then create a table named Table1,insert some data。Why it ONLY deletes 2 record? not all of them? Thanks a lot!

Option Explicit
Dim myConn As ADODB.Connection
Dim myRecord As ADODB.Recordset

Private Sub Form_Load()
Form1.Visible = True
DoEvents
Set myConn = New ADODB.Connection
myConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\tst.mdb;Persist Security Info=False"
myConn.Open
Set myRecord = New ADODB.Recordset
myRecord.Open "select * from Table1", myConn, adOpenDynamic, adLockOptimistic
Do Until myRecord.EOF
Debug.Print "Deleteing"
myRecord.Delete
myRecord.MoveNext
Loop
myRecord.Close
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set myRecord = Nothing
Set myConn = Nothing
End Sub

Report
Re: Is this a BUG of M$? Posted by GideonOmega on 17 Feb 2006 at 6:17 AM
: First,Create tst.mdb on drive D,then create a table named Table1,insert some data。Why it ONLY deletes 2 record? not all of them? Thanks a lot!
:
: Option Explicit
: Dim myConn As ADODB.Connection
: Dim myRecord As ADODB.Recordset
:
: Private Sub Form_Load()
: Form1.Visible = True
: DoEvents
: Set myConn = New ADODB.Connection
: myConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\tst.mdb;Persist Security Info=False"
: myConn.Open
: Set myRecord = New ADODB.Recordset
: myRecord.Open "select * from Table1", myConn, adOpenDynamic, adLockOptimistic
: Do Until myRecord.EOF
: Debug.Print "Deleteing"
: myRecord.Delete
: myRecord.MoveNext
: Loop
: myRecord.Close
: End Sub
:
: Private Sub Form_Unload(Cancel As Integer)
: Set myRecord = Nothing
: Set myConn = Nothing
: End Sub
:
:


Try adding MyRecord.MoveFirst before your loop that way you are at the begining of your recordset - otherwise you will just delete everything from the point you are at.

C:\Dos
C:\Dos Run
Run Dos Run


Report
Re: Is this a BUG of M$? Posted by tony0 on 20 Feb 2006 at 10:38 PM
: : First,Create tst.mdb on drive D,then create a table named Table1,insert some data。Why it ONLY deletes 2 record? not all of them? Thanks a lot!
: :
: : Option Explicit
: : Dim myConn As ADODB.Connection
: : Dim myRecord As ADODB.Recordset
: :
: : Private Sub Form_Load()
: : Form1.Visible = True
: : DoEvents
: : Set myConn = New ADODB.Connection
: : myConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\tst.mdb;Persist Security Info=False"
: : myConn.Open
: : Set myRecord = New ADODB.Recordset
: : myRecord.Open "select * from Table1", myConn, adOpenDynamic, adLockOptimistic
: : Do Until myRecord.EOF
: : Debug.Print "Deleteing"
: : myRecord.Delete
: : myRecord.MoveNext
: : Loop
: : myRecord.Close
: : End Sub
: :
: : Private Sub Form_Unload(Cancel As Integer)
: : Set myRecord = Nothing
: : Set myConn = Nothing
: : End Sub
: :
: :
:
:
: Try adding MyRecord.MoveFirst before your loop that way you are at the begining of your recordset - otherwise you will just delete everything from the point you are at.
:
: C:\Dos
: C:\Dos Run
: Run Dos Run
:

:
:

I know the problem now, add "myConn.CursorLocation = adUseClient" and "myRecord.CursorLocation = adUseClient", i'll work ok.

thanks for you help.
Report
Re: Is this a BUG of M$? Posted by Termc1224 on 16 Mar 2006 at 11:48 PM
: : : First,Create tst.mdb on drive D,then create a table named Table1,insert some data。Why it ONLY deletes 2 record? not all of them? Thanks a lot!
: : :
: : : Option Explicit
: : : Dim myConn As ADODB.Connection
: : : Dim myRecord As ADODB.Recordset
: : :
: : : Private Sub Form_Load()
: : : Form1.Visible = True
: : : DoEvents
: : : Set myConn = New ADODB.Connection
: : : myConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\tst.mdb;Persist Security Info=False"
: : : myConn.Open
: : : Set myRecord = New ADODB.Recordset
: : : myRecord.Open "select * from Table1", myConn, adOpenDynamic, adLockOptimistic
: : : Do Until myRecord.EOF
: : : Debug.Print "Deleteing"
: : : myRecord.Delete
: : : myRecord.MoveNext
: : : Loop
: : : myRecord.Close
: : : End Sub
: : :
: : : Private Sub Form_Unload(Cancel As Integer)
: : : Set myRecord = Nothing
: : : Set myConn = Nothing
: : : End Sub
: : :
: : :
: :
: :
: : Try adding MyRecord.MoveFirst before your loop that way you are at the begining of your recordset - otherwise you will just delete everything from the point you are at.
: :
: : C:\Dos
: : C:\Dos Run
: : Run Dos Run
: :

: :
: :
:
: I know the problem now, add "myConn.CursorLocation = adUseClient" and "myRecord.CursorLocation = adUseClient", i'll work ok.
:
: thanks for you help.
:

To delete all use this
: : : myRecord.Open "delete * from Table1", myConn, adOpenDynamic, adLockOptimistic, aduseclient




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.