Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2004
    Location
    UK
    Posts
    2

    Question Unanswered: ADOX Columns and Keys

    Hi,

    I am having some difficulty using ADOX to retreive information ABOUT a database. (Not FROM it).

    I want to know how (or if) it is possible to determine whether a Column in the Columns collection of an ADOX Table object is a Key column.

    I am running the following code:

    Code:
    for each column in tableObj.Columns
       if(column.RelatedColumn = "") then
          response.write(column.name & "<br/>")
       end if
    next
    The problem is that I get an error because I am trying to access the RelatedColumn property of non-Key columns.

    The online MSDN documentation is very unclear on this issue, RelatedColumn IS listed as a property of Column, but with the proviso that is only "for key columns". However the rest of the documentation indicates that Keys and Columns are entirely seperate objects with their own collections inside Table objects.

    What i am trying to do is populate a drop down list with the names of all Columns that are NOT keys, but how can I determine which ones these are?

    All help greatly appreciated!

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    I've never tried to use this before but I just had a look through MSDN. What you are doing would appear to be fine but from what you are saying I can understand what is happening....

    This isn't an elegant solution but it may help...

    Code:
    on error resume next
    for each column in tableObj.Columns
       if(column.RelatedColumn = "") then
          if err.number = 0 then response.write(column.name & "<br/>")
       end if
       if err.number <> 0 then err.clear
    next
    on error goto 0
    I wonder if there is a way to go through the properties collection of the column and determine if one of the properties is RelatedColumn and only if it is to grab it.... something like...

    Code:
    for each column in tableObj.Columns
       for each property in column.properties
          if property.name = "RelatedColumn" then
             if(column.RelatedColumn = "") then response.write(column.name & "<br/>")
          end if
       end if
    next
    HTH

  3. #3
    Join Date
    Jul 2004
    Location
    UK
    Posts
    2

    Arrow Thanks,

    That seems a good idea, should have thought of it myself, thanks.

    Regarding checking properties, apparently the contents of the properties collection depends on the Data Provider, and although this appears to be documented for ADO, I could find nothing for ADOX about this.

    Thanks for your help!

Posting Permissions

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