如何获得Constraint的名字?

时间:2009-05-22 19:45:06

标签: ms-access jet constraints

我正在使用MS Access数据库并尝试从C#2.0获取完整数据。 如何使用ADOX获取constriant名称(例如:Primarykey的名称而不是主键的字段名称)。

提前致谢 马杜

1 个答案:

答案 0 :(得分: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