If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > how to use ado to get primary key information?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-21-02, 07:54
laserdisk laserdisk is offline
Junior Member
 
Join Date: May 2002
Posts: 1
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
Reply With Quote
  #2 (permalink)  
Old 06-25-03, 20:50
Melly Melly is offline
Registered User
 
Join Date: Jun 2003
Location: Long Beach CA
Posts: 1
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!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On