LOCAL oCat As "adox.catalog" LOCAL oTable As "Adox.table" LOCAL oConn As "Adodb.connection" LOCAL oIdx As "adox.index" *-- Setup code SET EXCLUSIVE Off Clear RELEASE ALL CLOSE ALL CLEAR ALL IF File("TestDBC.DBC") Erase TestDBC.DBC Endif IF File("TestDBC.Dct") Erase TestDBC.Dct Endif IF File("TestDBC.Dcx") Erase TestDBC.Dcx Endif IF File("TestTable2.dbf") Erase TestTable2.dbf Endif IF File("TestTable2.cdx") Erase TestTable2.cdx Endif CREATE DATABASE TestDBC CLOSE DATABASES All oCat = CREATEOBJECT("adox.catalog") oTable = CREATEOBJECT("adox.table") oConn = CREATEOBJECT("adodb.connection") oConn.ConnectionString = "Provider=Vfpoledb.vfpoledb;Data Source=.\TestDBC.dbc" oConn.Open oCat.ActiveConnection = oConn oTable.Name = "testtable2" oTable.Columns.Append("Col_char", 129) oTable.Columns.Append("Col_Date", 133) oTable.Columns.Append("Col_DBDate", 135) oTable.Columns.Append("Col_int", 3) oTable.Columns.Append("Col_dbl", 5) oTable.Columns.Append("Col_cy", 6) oTable.Columns.Append("Col_bool", 11) *-- Have to this one differently, because it's the *-- only way to set the precision before appending *-- to the Columns collection. oCol = CREATEOBJECT("adox.column") oCol.Name = "Col_Num" oCol.Type = 131 && adNumeric oCol.Precision = 1 oTable.Columns.Append(oCol) oCat.Tables.Append(oTable) ? "Indexes before append:" ? oTable.Indexes.Count *-- Append indexes to the table in ascending order i = 0 FOR Each Child in oTable.Columns oIdx = CREATEOBJECT("adox.index") oIdx.Columns.Append(oTable.Columns(i).Name) oIdx.Columns(0).SortOrder = 1 && adSortAscending *-- Make sure the name is ten characters, and trim the "col_" from *-- the column name oIdx.Name = Substr("A_" + Substr(oTable.Columns(i).Name, 4), 1, 10) oTable.Indexes.Append(oIdx) oIdx = Null i = i + 1 Endfor ? "Indexes after appending ascending:" ? oTable.Indexes.Count *-- Append descending indexes i = 0 FOR Each Child in oTable.Columns oIdx = CREATEOBJECT("adox.index") oIdx.Columns.Append(oTable.Columns(i).Name) oIdx.Columns(0).SortOrder = 2 && adSortAscending *-- Make sure the name is ten characters, and trim the "col_" from *-- the column name oIdx.Name = Substr("D_" + Substr(oTable.Columns(i).Name, 4), 1, 10) oTable.Indexes.Append(oIdx) oIdx = Null i = i + 1 Endfor ? "Indexes after appending descending:" ? oTable.Indexes.Count *-- Release the table object and try again oTable = Null oTable = CREATEOBJECT("adox.table") oTable = oCat.Tables.Item(0) ? "Indexes after releasing table:" ? oTable.Indexes.Count *-- Cleanup RELEASE ALL CLOSE ALL CLEAR ALL