Skip to content

Latest commit

 

History

History
73 lines (63 loc) · 2.26 KB

File metadata and controls

73 lines (63 loc) · 2.26 KB
title Clustered Property Example (VB) | Microsoft Docs
ms.prod sql
ms.prod_service connectivity
ms.technology connectivity
ms.custom
ms.date 01/19/2017
ms.reviewer
ms.topic conceptual
dev_langs
VB
helpviewer_keywords
Clustered property [ADOX], Visual Basic example
ms.assetid 1cd30769-c8af-43e7-be27-12ed0434daa1
author MightyPen
ms.author genemi

Clustered Property Example (VB)

This example demonstrates the Clustered property of an Index. Note that Microsoft Jet databases do not support clustered indexes, so this example will return False for the Clustered property of all indexes in the Northwind database.

' BeginClusteredVB  
Sub Main()  
    On Error GoTo ClusteredXError  
  
    Dim cnn As New ADODB.Connection  
    Dim cat As New ADOX.Catalog  
    Dim tblLoop As ADOX.Table  
    Dim idxLoop As ADOX.Index  
    Dim strCnn As String  
  
    strCnn = "Provider='SQLOLEDB';Data Source='MySqlServer';Initial Catalog='pubs';" & _  
        "Integrated Security='SSPI';"  
    ' Connect to the catalog.  
    cnn.Open strCnn  
    cat.ActiveConnection = cnn  
  
    ' Enumerate the tables.  
    For Each tblLoop In cat.Tables  
        'Enumerate the indexes.  
        For Each idxLoop In tblLoop.Indexes  
            Debug.Print tblLoop.Name & " " & _  
                idxLoop.Name & " " & idxLoop.Clustered  
        Next idxLoop  
    Next tblLoop  
  
    'Clean up.  
    cnn.Close  
    Set cat = Nothing  
    Set cnn = Nothing  
    Exit Sub  
  
ClusteredXError:  
  
    Set cat = Nothing  
  
    If Not cnn Is Nothing Then  
        If cnn.State = adStateOpen Then cnn.Close  
    End If  
    Set cnn = Nothing  
  
    If Err <> 0 Then  
        MsgBox Err.Source & "-->" & Err.Description, , "Error"  
    End If  
End Sub  
' EndClusteredVB  

See Also

Catalog Object (ADOX)
Clustered Property (ADOX)
Index Object (ADOX)
Table Object (ADOX)