-1

How can I get index names for an Access table using OLEDB or SQL ?

(I searched a lot on the internet in the last two days and did not find anything related to this issue.)

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
  • 1
    Did you try to put your title in a search engine? [I have done it for you](http://www.bing.com/search?q=How%20can%20I%20get%20index%20name%20from%20a%20Access%20table%20using%20OLdb%20or%20SQL%20&qs=n&sk=&form=BDKTKB&pc=BDT5&shash=&BDParam=2000&mkt=en-US) – Steve Jan 27 '15 at 16:31
  • https://stackoverflow.com/questions/2536955/retrieve-list-of-indexes-in-an-access-database – Raj More Jan 27 '15 at 16:32
  • it's amazing what a simple `Google Search can Yield` http://www.wenda.io/questions/4481409/how-to-get-all-table-name-and-also-column-name-ms-access-in-c-sharp.html – MethodMan Jan 27 '15 at 16:34
  • Rather than the wenda.io linkbait, here's the underlying stackoverflow question: http://stackoverflow.com/questions/15978225/how-to-get-all-table-names-and-also-column-name-using-c-sharp-in-ms-access – J. Steen Jan 27 '15 at 16:36

1 Answers1

3

The OleDbConnection has a method called GetSchema that takes a string to select the collection of metadata that you want to retrieve.

Some of the possible values for the string parameter are Tables, Columns, Indexes

using(OleDbConnection cnn = new OleDbConnection("...."))
{
    cnn.Open();
    DataTable schemaIndexes = cnn.GetSchema("Indexes");
    foreach(DataRow row in schemaIndexes.Rows)
    {
       Console.WriteLine("Table={0}, Index={1} on field={2}",
           row.Field<string>("TABLE_NAME"),
           row.Field<string>("INDEX_NAME"),
           row.Field<string>("COLUMN_NAME"));
    }
}
Steve
  • 213,761
  • 22
  • 232
  • 286