1.6 Recordset Object

Represents the entire set of records from a base table or the results of an executed command.

At any time, this object refers only to a single record within the set as the current record. This object must be associated with a valid connection object or have a valid connection string assigned to it before any other methods or properties are called or set.

1.6.1 ActiveConnection property

Indicates which Connection object the Recordset object currently belongs to.

Syntax

object.ActiveConnection

Type

String. Sets or returns a String containing the definition for a connection or a Connection object. Default is a NULL object reference.

Attributes

Read/write.

Remarks

The format of the connection string is similar to an ODBC connection string. For example: DBType=0;Database=MyServer-TCP.World;UID=Scott;PWD=Tiger

DBType - The valid types are 0 for an Oracle 8 database or 1 for a B2System SQLIntegrator database. Database - Any valid database name that corresponds to the database type specified by DBType. UID - A valid user ID for the database. PWD - A valid password for the user ID and database.

1.6.2 Eof property

Indicates that the current record position is after the last record in a Recordset object.

Syntax

object.Eof

Type

Boolean.

Attributes

Read-only.

1.6.3 Fields property

A collection of Field objects that correspond to the fields held by the current Recordset object.

Syntax

object.Fields

Type

Fields

Attributes

Read-only.

1.6.4 Source property

Indicates the data source for a Recordset object.

Syntax

Object.Source

Type

String.

Attributes

Read-only.

1.6.5 Close method

Closes an open Recordset object and any dependent objects.

Syntax

object.Close()

Parameters

None.

Return Values

None.

See Also

1.6.6 MoveNext method

Moves to the next record in a specified Recordset object and makes that record the current record.

Syntax

object.MoveNext()

Parameters

None.

Return Values

None.

1.6.7 Open method

Opens a Recordset object.

Syntax

object.Open(
   Source As Variant, 
   ActiveConnection As Variant or String, 
   CursorType As CursorTypeEnum, 
   LockType As LockTypeEnum)

Parameters

Source

Evaluates to a valid Command object, an SQL statement, a table name, or a stored procedure call. (Currently supports only SQL statements or Command objects.)

ActiveConnection

Either a Variant that evaluates to a valid Connection object, or a String containing ConnectionString parameters. See the ConnectionString property for a description of the connection string format.

Return Values

None.

Remarks

If the ActiveConnection property used to open the Recordset is a connection string, the ActiveConnection object returned by the ActiveConnection property is valid only for the lifetime of the Recordset object. If the Recordset object is closed, the ActiveConnection is also closed.

1.6.8 Sample Script for RecordSet object

This sample script prints details about all the departments.The sample does the following:

’This sample script for RecordSet object
Option VBA
On Error Resume Next

Set CN = CreateObject("UCX:NDODB.CONNECTION")
CN.Open ("DBTYPE=0;DATABASE=ORANW81.WORLD", "scott","Tiger")
Set RS = CN.Execute("Select * from dept", lRec)
If Err <> 0 Then
   GoTo errorhandler
End If
DisplayRS (RS)’ Print the details about the recordset
’
Print RS.ActiveConnection
Print RS.Source
RS.Close
’Insert a new department
’
CN.Execute ("Insert into deptvalues(78,’Books’,’Boston’)",lRec)
RS.Requery
DisplayRS (RS)
CN.CommitTrans
CN.Close
RS.Close

’ Subroutine to display the details of a record set.
’
Sub DisplayRS(RS As Object)
Dim FLDS As Object
Dim FLD As Object
Dim RecValue As String
Dim FldCount As Long
    Set FLDS = RS.Fields
    RecValue = ""
    For FldCount = 1 To FLDS.Count
        Set FLD = FLDS.Item(FldCount)
        RecValue = RecValue & " " & CStr(FLD.Name)
    Next
    Print RecValue
    PrintLine (60)
    Do
        RecValue = ""
        For FldCount = 1 To FLDS.Count
            Set FLD = FLDS.Item(FldCount)
            RecValue = RecValue & " " & CStr(FLD.Value)
        Next
        Print RecValue
        RS.MoveNext
    Loop While Not RS.EOF
End Sub

’Subroutine to print a line
’
Sub PrintLine(Number)
    For PrintCount = 1 To Number
        Line = Line & "-"
    Next
    Print Line
End Sub