Getting Foreign Key information of an ADO.Recordset Field

Hi,

I am writing a VB6 application that is designed to be generic so a lot of meta-data is stored in SQL Server 2000 database, with controls being dynamically added to forms based on database settings.  

Currently in my metadata table I have a column called DataListSQL which is used to store the SQL required to populate the combobox control, and have another field to say what type of control it is (Combobox, Textbox, Checkbox, Label).

I want to miminise the amount of work required for the administration so I was hoping to programmatically determine the type of control to be displayed based on the field data type.  The problem is I don't know how to determine from the Adodb.recordset if a field is a foreign key and so should be a combobox.  If it is a foreign key column I would like to know the foreign key table and column name so I can select all the values from this table to populate the combobox control.

I hope this makes sense to people outside my head ;)
LVL 1
osullilAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leonstrykerCommented:
You have two options here.  The first option is to add a column to your table which will identify if the column is part of a foreign key, or you may run the sp_fkeys system store procedure in order to retrieve this information:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sp_fa-fz_65yr.asp

Leon
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
osullilAuthor Commented:
The second option is the best as I want to remove as much of the meta data information to try and minimise the margin of error when configuring.  I had hoped though that there would be some way to get information through ADO recordset to avoid having to send another query to database.
0
leonstrykerCommented:
>>I had hoped though that there would be some way to get information through ADO recordset to avoid having to send another query to database.

You should create a store procedure which does this for you.  That way you would still need to make only one call the server.

Leon
0
osullilAuthor Commented:
Stored procedure would be a little tricky seeing as the query to retrieve data is programmatically generated based on meta data table which stores table and column names used by the dynamic controls.  I will add the sp_fkeys call as part of this batch though so still only one call to server and use the rs.Nextrecordset to get to foreign keys recordset.

Thanks for the help on this
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.