Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic detection of Primary key in ADO

Status
Not open for further replies.

pjani

Programmer
Apr 16, 2001
9
0
0
US
Hi,

In following sample code dbTest connects to MS Access 2k database. I am showing all the fields in Table1 to list2 listbox.

List2.Clear
str = "Table1"

Set tdtest = dbTest.TableDefs(str)

For Each fdtest In tdtest.Fields
List2.AddItem fdtest.Name
str$ = fdtest.Type
Next

My question is if field1, field2, field3 are present in Table1 then how to detect at run time which field is the primary key?
Also please tell me, how to do above using ADO?

Thank you for your time,
pjani
 
Add a reference to ADOX (Microsoft ADO Ext. 2.6 for DDL and Security) to your project.

You set the ActiveConnection in the Catalog object, then navigate through the tables and keys collection to get the info you want.

Chip H.
 
Hi Chiph,

Thank you for your guidance. I am now kind of comfortable with ADOX, but i wonder if I can do this using only ADO 2.1 this way i can save a extra reference to MS ADO Extension 2.5
My Win 98 pc have visual studio 6.0 and sp 3 and ADOX 2.5...i could not find ADOX 2.6
 
for ADO 2.6 you have need Windows 2000

Thanks, Eric. I didn't know that.

I've been runing Windows 2000 so long now that I sometimes forget that other people aren't on it yet.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top