2013-06-19 27 views

回答

2

似乎檢索.Indexes當限制陣列的第三構件對應於所述索引名稱,而不是名稱。因此,要檢索給定表的索引,它看起來像我們需要檢索所有索引(沒有限制),然後篩選出我們不想要的索引。

下面的C#代碼工作對我來說:

using (OleDbConnection con = new OleDbConnection()) 
{ 
    con.ConnectionString = myConnectionString; 
    con.Open(); 
    object[] restrictions = new object[3]; 
    System.Data.DataTable table = con.GetOleDbSchemaTable(OleDbSchemaGuid.Indexes, restrictions); 

    // Display the contents of the table. 
    foreach (System.Data.DataRow row in table.Rows) 
    { 
     string tableName = row[2].ToString(); 
     if (tableName == "Clients") 
     { 
      foreach (System.Data.DataColumn col in table.Columns) 
      { 
       Console.WriteLine("{0} = {1}", 
        col.ColumnName, row[col]); 
      } 
      Console.WriteLine("============================"); 
     } 
    } 
    con.Close(); 
} 
+0

感謝這個,很快就會給它一去。 – twilson

+0

工作過。乾杯。 – twilson