views:

143

answers:

1

Hi, I am using MS Access Database and trying to full data from C# 2.0. How can i get the constriant name (Eg: name of Primarykey not the field name of primary key) using ADOX.

Thanks in advance Madhu

A: 

From: 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
Remou
Thank you Remou. Thats works. You saved lot of my time.
Madhu kiran