2009-05-22 88 views
0

我正在使用MS Access數據庫並嘗試從C#2.0獲取完整數據。 如何使用ADOX獲取constriant名稱(例如:Primarykey的名稱,而不是主鍵的字段名稱)。如何獲得約束的名稱?

在此先感謝 馬杜

回答

0

來源:How To Use ADOX to Determine If a Primary Key Exists on a Table

SQL = "CREATE TABLE PKTEST1 (f1 INT PRIMARY KEY, f2 INT)" 
cn.Execute SQL 

Set cat.ActiveConnection = cn 

'Check all indexes on the table for a primary key' 
For Each idx In cat.Tables("PKTEST1").Indexes 
     If idx.PrimaryKey = True Then 
     Debug.Print "INDEX NAME: " & idx.Name 

     'Show all columns that make up the index' 
     Debug.Print "consists of the following columns:" 
     For i = 0 To idx.Columns.Count - 1 
      Debug.Print idx.Columns(i).Name 
     Next 

    End If 

Next 
+0

謝謝Remou。那是行得通的。你節省了很多我的時間。 – 2009-05-22 20:54:01