Getting Foreign Key information of an ADO.Recordset Field

Posted on 2004-10-27
Last Modified: 2013-12-25

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 ;)
Question by:osullil
    LVL 29

    Accepted Solution

    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:

    LVL 1

    Author Comment

    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.
    LVL 29

    Expert Comment

    >>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.

    LVL 1

    Author Comment

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Shellfire Box VPN + Lifetime Subscription

    The Shellfire Box easily connects all of your devices, even those that don't offer the possibility to establish a safe vpn connection. Access blocked content and surf safely, no matter where in the world you are located.

    Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now