Unanswered: how to use ado to get primary key information?
I've tried the following function, which someone else wrote to use, but to no avail?
Dim cn As New ADODB.Connection
strUrl = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=VAPMiningBase;Data Source=server"
Public Function FindPK(TableName As String) As Variant
Dim cat As ADOX.Catalog, key As ADOX.key, tbl As ADOX.Table, col As ADOX.Column
Set cat = New ADOX.Catalog
cat.ActiveConnection = cn
Set tbl = cat.Tables(TableName)
For Each key In tbl.Keys
If key.Type = adKeyPrimary Then
FindPK = key.Name
'this is some other information that may be useful
Debug.Print " Key Name = " & key.Name
Debug.Print " Key Type = " & key.Type
Debug.Print "Num columns = " & key.Columns.Count
For Each col In key.Columns
Debug.Print "Column Name = " & col.Name
FindPK = Null
when function execute key.Columns.Count,run error "3251" occured
"The operation requested by the application is not supported by the provider"
why,what means is it?
how can i get primary key?
who can help me,Thanks a lot