该范例显示 Connection、Field 和 Property 对象的 Attributes 属性值。它使用 Name 属性显示每个 Field 和 Property 对象的名称。
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