|
|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
ADO: Moving To The Next Record In A Record SetTo move to the next record in an ADO record set, you use the Recordset objects MoveNext method (this method takes no parameters). Lets see an example. When the user clicks the appropriate button in our ADO code example, the adocode example (see A Full-Scale ADO Example in this chapter), well move to the next record in our record set, adoRecordset. Note that we make sure we dont move past the end of the record set by checking the record sets EOF property:
Private Sub cmdNext_Click()
On Error GoTo ErrLabel
If Not adoRecordset.EOF Then
adoRecordset.MoveNext
End If
If adoRecordset.EOF And adoRecordset.RecordCount > 0 Then
adoRecordset.MoveLast
End If
Exit Sub
ErrLabel:
MsgBox Err.Description
End Sub
ADO: Moving To The Previous Record In A Record SetTo move to the next record in an ADO record set, you use the Recordset objects MovePrevious method (this method takes no parameters). Lets see an example. When the user clicks the appropriate button in our ADO code example, the adocode example (see A Full-Scale ADO Example in this chapter), well move to the previous record in our record set, adoRecordset. Note that we make sure we dont move past the end of the record set by checking the record sets BOF property:
Private Sub cmdPrevious_Click()
On Error GoTo ErrLabel
If Not adoRecordset.BOF Then adoRecordset.MovePrevious
If adoRecordset.BOF And adoRecordset.RecordCount > 0 Then
adoRecordset.MoveFirst
End If
Exit Sub
ErrLabel:
MsgBox Err.Description
End Sub
ADO: Deleting A Record In A Record SetTo delete a record in an ADO record set, you use the Delete method: recordset.Delete AffectRecords Here, AffectRecords is a value that determines how many records the Delete method will affect. It can be one of the following constants:
Lets see an example. Here, we delete a record in our ADO code example, the adocode example (see A Full-Scale ADO Example in this chapter), when the user presses the appropriate button:
Private Sub cmdDelete_Click()
On Error GoTo ErrLabel
adoRecordset.Delete
...
In addition, we move to the next record this way:
Private Sub cmdDelete_Click()
On Error GoTo ErrLabel
adoRecordset.Delete
adoRecordset.MoveNext
If adoRecordset.EOF Then
adoRecordset.MoveLast
End If
Exit Sub
ErrLabel:
MsgBox Err.Description
End Sub
And thats itnow weve deleted a record. ADO: Executing SQL In A Record SetYou can execute an SQL statement when you open a record set using the Open method by passing that statement as the Source argument: recordset.Open [ Source, [ActiveConnection, [Type, [LockType, [Options]]]] Here are the arguments for this method:
Here are the possible values for the Type argument:
Here are the possible values for the LockType argument:
Here are the possible values for the Options argument:
Heres an example where we open a record set with the SQL statement select * from students: adoRecordset.Open "select * from students", db, adOpenStatic, adLockOptimistic
|
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |