Results 1 to 7 of 7

Thread: Querying a Access Database

  1. #1

    Thread Starter
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067

    Querying a Access Database

    Can someome possibly post an example to do what I want.
    I am using the openschema method of a ADO connection to itterate through the list of queries in a database.
    What I wan to extract is the list of fields the query is using and the associated table that the field comes from.
    I have already done this for the list of tables but I cannot use the same code for the queries (or as in the openschema method, "VIEW").
    O have already looked at the examples in the MSDN but they only seem to list all the available VIEWS, not the actual fields.

    Thanks.
    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  2. #2
    Member
    Join Date
    Nov 2002
    Location
    Australia
    Posts
    34
    This is taken from an old Database Analyser app i wrote a while back.
    I've removed a lot of the code (it also displayed keys, field sizes, etc) but it should give you an idea of how to go about doing what you need. I know you already have your code set up to get the tables, but you could use the same routine below to do the same thing (just look for type "TABLE" instead of "VIEW")

    VB Code:
    1. Private cat As New ADOX.Catalog
    2. Private tbl As New ADOX.Table
    3.  
    4. For Each tbl In cat.Tables
    5.  
    6.     If InStr(1, tbl.Name, "MSys", vbTextCompare) = 0 And tbl.Type = "VIEW" Then
    7.    
    8.         txtOutput = txtOutput & tbl.Name & vbCrLf
    9.        
    10.         For i = 0 To tbl.Columns.Count - 1
    11.        
    12.             txtOutput = txtOutput & vbTab & tbl.Columns(i).Name
    13.                
    14.         Next i
    15.        
    16.         txtOutput = txtOutput & vbCrLf
    17.        
    18.     End If
    19.  
    20. Next tbl

  3. #3

    Thread Starter
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Ok, thanks. Another question though.Does this list the associated table that the field in the query comes from ?

    e.g.

    Query Name : QryCountCalls

    Fields : Call ID
    Table name : Call Details

    Fields : Call Count
    Table name : None (Expression variable).

    Do you know what I mean?

    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  4. #4
    Lively Member
    Join Date
    Apr 2002
    Location
    UK
    Posts
    90
    Thers a free OpenSchema gui in adoanywhere that exposes all enums.

    here is a link to .net in case you need it in future http://support.microsoft.com/default...b;EN-US;309488

    adoanywhere open schema gui
    Mike Collier
    Free ADO & DotNet Tools and Source
    AdoAnywhere


  5. #5

    Thread Starter
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Thanks,
    I have enough to go on now.

    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  6. #6

    Thread Starter
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Ok,
    I now have a follow up question for this.

    I can now itterate through the queries and list the columns in the query, however, if the query requires a parameter to be passed, I get errors.
    I am going through loads of queries and I don't know which ones need parameters and how many. Is there anyway of getting the code to ignore this and give me the column name anyway?

    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  7. #7

    Thread Starter
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Bump
    "If at first you don't succeed, then skydiving is not for you"

Posting Permissions

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



Click Here to Expand Forum to Full Width