MDAC 2.5 SDK - ADOX


 

Indexes Append Method Example (VB)

See Also

The following code demonstrates how to create a new index. The index is on two columns in the table.

Sub CreateIndex()

   Dim tbl As New Table
   Dim idx As New ADOX.Index
   Dim cat As New ADOX.Catalog

'Open the catalog.
   ' Open the Catalog.
   cat.ActiveConnection = _ 
      "Provider=Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source=c:\Program Files\Microsoft Office\" & _
      "Office\Samples\Northwind.mdb;"

   ' Define the table and append it to the catalog
   tbl.Name = "MyTable"
   tbl.Columns.Append "Column1", adInteger
   tbl.Columns.Append "Column2", adInteger
   tbl.Columns.Append "Column3", adVarWChar, 50
   cat.Tables.Append tbl

   ' Define a multi-column index
   idx.Name = "multicolidx"
   idx.Columns.Append "Column1"
   idx.Columns.Append "Column2"

   ' Append the index to the table
   tbl.Indexes.Append idx

End Sub