該范例顯示 Connection、Field 和 Property 對(duì)象的 Attributes 屬性值。它使用 Name 屬性顯示每個(gè) Field 和 Property 對(duì)象的名稱。
Public Sub AttributesX
Dim cnn1 As ADODB.Connection
Dim rstEmployees As ADODB.Recordset
Dim fldLoop As ADODB.Field
Dim proLoop As ADODB.Property
Dim strCnn As String
' 打開連接和記錄集。
strCnn = "Provider=sqloledb;" & _
"Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "
Set cnn1 = New ADODB.Connection
cnn1.Open strCnn
Set rstEmployees = New ADODB.Recordset
rstEmployees.Open "employee", cnn1, , , adCmdTable
' 顯示連接的屬性。
Debug.Print "Connection attributes = " & _
cnn1.Attributes
' 顯示雇員表字段的屬性。
Debug.Print "Field attributes:"
For Each fldLoop In rstEmployees.Fields
Debug.Print " " & fldLoop.Name & " = " & _
fldLoop.Attributes
Next fldLoop
' 顯示是 NULLABLE 的雇員表的字段。
Debug.Print "NULLABLE Fields:"
For Each fldLoop In rstEmployees.Fields
If CBool(fldLoop.Attributes And adFldIsNullable) Then
Debug.Print " " & fldLoop.Name
End If
Next fldLoop
' 顯示雇員表屬性的屬性。
Debug.Print "Property attributes:"
For Each proLoop In rstEmployees.Properties
Debug.Print " " & proLoop.Name & " = " & _
proLoop.Attributes
Next proLoop
rstEmployees.Close
cnn1.Close
End Sub