Sun Chili!Soft ASP Sun Chili!Soft
ASP Sun Microsystems

 

ADO Collections Count Property

The number of objects in a collection.

Count Property Applies To

ADO Errors Collection, ADO Fields Collection, ADO Parameters Collection, ADO Properties Collection

Count Property Return Values

Returns a Long value.

Count Property Remarks

Use the Count property to determine how many objects are in a given collection.

Because numbering for members of a collection begins with zero, you should always code loops starting with the zero member and ending with the value of the Count property minus one. If you are using Visual Basic and want to loop through the members of a collection without checking the Count property, use the For Each...Next command.

If the Count property is zero, there are no objects in the collection.

Count Property Example

This Visual Basic example demonstrates the Count property with two collections in the Employee database. The property obtains the number of objects in each collection, and sets the upper limit for loops that enumerate these collections. Another way to enumerate these collections without using the Count property would be to use For Each...Next statements.

Public Sub CountX()

Dim rstEmployees As ADODB.Recordset

Dim strCnn As String

Dim intloop As Integer

' Open recordset with data from Employee table.

strCnn = "driver={SQL Server};server=srv;" & _

"uid=sa;pwd=;database=pubs"

Set rstEmployees = New ADODB.Recordset

rstEmployees.Open "employee", strCnn, , , adCmdTable

' Print information about Fields collection.

Debug.Print rstEmployees.Fields.Count & _

" Fields in Employee"

For intloop = 0 To rstEmployees.Fields.Count - 1

Debug.Print " " & rstEmployees.Fields(intloop).Name

Next intloop

' Print information about Properties collection.

Debug.Print rstEmployees.Properties.Count & _

" Properties in Employee"

For intloop = 0 To rstEmployees.Properties.Count - 1 Debug.Print " " & rstEmployees.Properties(intloop).Name

Next intloop

rstEmployees.Close

End Sub

Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.