|
|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
RDO: Moving To The First Record In A Result SetTo move to the first record in an RDO result set, you can use the rdoResultset method MoveFirst. Lets see an example. In this case, well move to the first record in the result set named resultset that weve opened in our RDO code example, the rdocode project (see A Full-Scale RDO Example earlier in this chapter), when the user clicks the appropriate button:
Private Sub cmdFirst_Click()
On Error GoTo ErrLabel
resultset.MoveFirst
...
Exit Sub
ErrLabel:
MsgBox Err.Description
End Sub
After moving to the new record, we display the data in that records fields in the programs text boxes, Text1 and Text2:
Private Sub cmdFirst_Click()
On Error GoTo ErrLabel
resultset.MoveFirst
Text1.Text = resultset("Name")
Text2.Text = resultset("Grade")
Exit Sub
ErrLabel:
MsgBox Err.Description
End Sub
RDO: Moving To The Last Record In A Result SetTo move to the last record in an RDO result set, you can use the rdoResultset method MoveLast. Lets see an example. In this case, well move to the last record in the result set named resultset that weve opened in our RDO code example, the rdocode project (see A Full-Scale RDO Example earlier in this chapter), when the user clicks the appropriate button:
Private Sub cmdLast_Click()
On Error GoTo ErrLabel
resultset.MoveLast
...
Exit Sub
ErrLabel:
MsgBox Err.Description
End Sub
After moving to the new record, we display the data in that records fields in the programs text boxes, Text1 and Text2:
Private Sub cmdLast_Click()
On Error GoTo ErrLabel
resultset.MoveLast
Text1.Text = resultset("Name")
Text2.Text = resultset("Grade")
Exit Sub
ErrLabel:
MsgBox Err.Description
End Sub
RDO: Moving To The Next Record In A Result SetTo move to the next record in an RDO result set, you can use the rdoResultset method MoveNext. Lets see an example. In this case, well move to the next record in the result set named resultset that weve opened in our RDO code example, the rdocode project (see A Full-Scale RDO Example earlier in this chapter), when the user clicks the appropriate button. We check to make sure were not trying to move past the end of the record set with the EOF property, and if so, we make sure to move to the last record instead:
Private Sub cmdNext_Click()
On Error GoTo ErrLabel
If Not resultset.EOF Then resultset.MoveNext
If resultset.EOF And resultset.RowCount > 0 Then
resultset.MoveLast
End If
...
Exit Sub
ErrLabel:
MsgBox Err.Description
End Sub
After moving to the new record, we display the data in that records fields in the programs text boxes, Text1 and Text2:
Private Sub cmdNext_Click()
On Error GoTo ErrLabel
If Not resultset.EOF Then resultset.MoveNext
If resultset.EOF And resultset.RowCount > 0 Then
resultset.MoveLast
End If
Text1.Text = resultset("Name")
Text2.Text = resultset("Grade")
Exit Sub
ErrLabel:
MsgBox Err.Description
End Sub
RDO: Moving To The Previous Record In A Result SetTo move to the previous record in an RDO result set, you can use the rdoResultset method MovePrevious. Lets see an example. In this case, well move to the previous record in the result set named resultset that weve opened in our RDO code example, the rdocode project (see A Full-Scale RDO Example earlier in this chapter), when the user clicks the appropriate button. We check to make sure were not trying to move past the beginning of the record set with the BOF property, and if so, we make sure to move to the first record instead:
Private Sub cmdPrevious_Click()
On Error GoTo ErrLabel
If Not resultset.BOF Then resultset.MovePrevious
If resultset.BOF And resultset.RowCount > 0 Then
resultset.MoveFirst
End If
Text1.Text = resultset("Name")
Text2.Text = resultset("Grade")
Exit Sub
ErrLabel:
MsgBox Err.Description
End Sub
After moving to the new record, we display the data in that records fields in the programs text boxes, Text1 and Text2:
Private Sub cmdPrevious_Click()
On Error GoTo ErrLabel
If Not resultset.BOF Then resultset.MovePrevious
If resultset.BOF And resultset.RowCount > 0 Then
resultset.MoveFirst
End If
Text1.Text = resultset("Name")
Text2.Text = resultset("Grade")
Exit Sub
ErrLabel:
MsgBox Err.Description
End Sub
RDO: Executing SQLYou can execute SQL statements with RDO objects when you open a result set, as we saw in RDO: Creating A Result Set in this chapter. You can also execute an SQL statement with the rdoConnection objects Execute statements like this: SQLSel = "Select * from students" rdoConnection.Execute SQLSel A Full-Scale ADO ExampleTo illustrate ADO data handling in code, well build an ADO projectthe adocode project. This application lets you open the db.mdb file we built in the previous chapter using ADO objects to edit records, add records, and even delete records. You can also move through the database using the arrow buttons you see in Figure 25.5.
To edit a record, just type the new value(s) into the text box(es) and click the Update button. To add a record, use the Add button, type the new value(s) into the text box(es), and click the Update button. Thats all there is to ityour changes will be reflected in the original database. For reference, the code for this example is located in the adocode folder on this books accompanying CD-ROM.
|
|
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. |