此頁(yè)沒(méi)有內(nèi)容條目
內(nèi)容

Count 屬性范例

該范例使用雇員數(shù)據(jù)庫(kù)中的兩個(gè)集合說(shuō)明 Count 屬性。該屬性獲得每個(gè)集合中的對(duì)象數(shù)并對(duì)枚舉這些集合的循環(huán)設(shè)置上限。另一種不通過(guò)使用 Count 屬性來(lái)枚舉這些集合的方法是使用 For Each...Next 語(yǔ)句。

Public Sub CountX()

   Dim rstEmployees As ADODB.Recordset

   Dim strCnn As String

   Dim intloop As Integer

   ' 使用雇員表中的數(shù)據(jù)打開(kāi)記錄集。

   strCnn = "Provider=sqloledb;" & _

      "Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "

   Set rstEmployees = New ADODB.Recordset

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

   ' 打印有關(guān)字段集合的信息。

   Debug.Print rstEmployees.Fields.Count & _

      " Fields in Employee"

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

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

   Next intloop

   ' 打印屬性集合的信息。

   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