Sun
ONE Active Server Pages Product Home Page Developer Site Version
 

ContentsPreviousNextIndex



ADO Recordset Object NextRecordset Method

Clears the current Recordset object and returns the next recordset by advancing through a series of commands. This method is not currently supported on UNIX.

NextRecordset Method Syntax
Set recordset2 = recordset1.NextRecordset( RecordsAffected )
NextRecordset Method Parameters

recordset2

Recordset containing results of command.

RecordsAffected

An optional Long variable to which the provider returns the number of records that the current operation affected.

NextRecordset Method Return Values

Returns a Recordset object. In the syntax model, recordset1 and recordset2 can be the same Recordset object, or you can use separate objects.

NextRecordset Method Remarks

Use the NextRecordset method to return the results of the next command in a compound command statement or of a stored procedure that returns multiple results. If you open a Recordset object based on a compound command statement (for example, "SELECT * FROM table1;SELECT * FROM table2") using the ADO Command Object Execute Method on an ADO Command Object or the ADO Recordset Object Open Method on a recordset, ADO executes only the first command and returns the results to recordset. To access the results of subsequent commands in the statement, call the NextRecordset method.

As long as there are additional results, the NextRecordset method will continue to return Recordset objects. If a row-returning command returns no records, the returned Recordset object will be empty; test for this case by verifying that the ADO Recordset Object BOF, EOF Properties are both True. If a non row-returning command executes successfully, the returned Recordset object will be closed, which you can verify by testing the ADO Recordset Object State Property on the recordset. When there are no more results, recordset will be set to Nothing.

If an edit is in progress while in immediate update mode, calling the NextRecordset method generates an error; call the ADO Recordset Object Update Method or the ADO Recordset Object CancelUpdate Method first.

If you need to pass parameters for more than one command in the compound statement by filling the ADO Parameters Collection or by passing an array with the original Open or Execute call, the parameters must be in the same order in the collection or array as their respective commands in the command series. You must finish reading all the results before reading output parameter values.

When you call the NextRecordset method, ADO executes only the next command in the statement. If you explicitly close the Recordset object before stepping through the entire command statement, ADO never executes the remaining commands.

The NextRecordset method is not available on a client-side (ADOR) Recordset object.

NextRecordset Method Example

This Visual Basic example uses the NextRecordset method to view the data in a recordset that uses a compound command statement made up of three separate SELECT statements.

Public Sub NextRecordsetX() 
Dim rstCompound As ADODB.Recordset 
Dim strCnn As String 
Dim intCount As Integer
` Open compound recordset. 
strCnn = "driver={SQL Server};server=srv;" & _ 
"uid=sa;pwd=;database=pubs" 
Set rstCompound = New ADODB.Recordset 
rstCompound.Open "SELECT * FROM authors; " & _ 
"SELECT * FROM stores; " & _ 
"SELECT * FROM jobs", strCnn, , , adCmdText
` Display results from each SELECT statement. 
intCount = 1 
Do Until rstCompound Is Nothing 
Debug.Print "Contents of recordset #" & intCount 
Do While Not rstCompound.EOF 
Debug.Print , rstCompound.Fields(0), _ 
rstCompound.Fields(1) 
rstCompound.MoveNext 
Loop 
Set rstCompound = rstCompound.NextRecordset 
intCount = intCount + 1 
Loop 
End Sub


ContentsPreviousNextIndex