Results 1 to 2 of 2
  1. #1
    Join Date
    May 2002

    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"
    cn.Open strUrl

    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
    Next col

    Exit Function
    End If
    FindPK = Null
    Next key
    End Function

    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

  2. #2
    Join Date
    Jun 2003
    Long Beach CA

    Arrow Visual Basic accessing Database

    I am having problems accessing my information off Access database from my Visual Basic program.

    Can someone show me the coding - mine is not working!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts