Results 1 to 5 of 5

Thread: Open schema column

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Location
    Newcastle
    Posts
    19

    Open schema column

    This is all on a button click
    I have this half working i can display all tables in data base in combo1 then the bit i cant get to work is to display all columns in that table in to combo2 any ideas searched the web cant find any help on it


    VB CODE
    _______________________________________________
    Set adox_Catalog = New ADOX.Catalog
    Set adox_Catalog.ActiveConnection = cnn
    For Each adox_Table In adox_Catalog.Tables
    If UCase(Left(adox_Table.Name, 4)) <> "MSYS" Then
    Combo1.AddItem adox_Table.Name
    End If
    Next adox_Table

    ____________________________________________________
    END CODE
    Last edited by david maddison; Apr 4th, 2003 at 03:52 AM.
    david

  2. #2
    Hyperactive Member
    Join Date
    Jan 2003
    Location
    Cape Cod, US
    Posts
    292
    here's a bit of old code I found where I used OpenSchema with ADO instead of ADOX to do something like what you want.

    I'm adding the col info to a recordset but I'm sure you won't have a problem adding it to the listbox/combo.

    For more details check out OpenSchema...

    VB Code:
    1. Dim rsTmp As New ADODB.Recordset
    2.        
    3. rsTmp.Fields.Append "TABLE", adWChar, 255
    4. rsTmp.Fields.Append "COLUMN", adWChar, 255
    5. rsTmp.Fields.Append "TYPE", adVarChar, 255
    6. rsTmp.Fields.Append "SEQ", adInteger
    7. rsTmp.Open
    8.  
    9. Dim conn As New ADODB.Connection
    10. conn.Open MyConnectionString
    11.        
    12. Set rs = conn.OpenSchema(adSchemaColumns, Array(Empty, Empty, rsTables(TABLE_NAME)))
    13.              
    14. Do While Not rs.EOF
    15.     rsTmp.AddNew Array(rs.Fields(2).Name, rs.Fields(3).Name, rs.Fields(11).Name, rs.Fields(6).Name), _
    16.                  Array(rs.Fields(2).Value, rs.Fields(3).Value, TypeName(rs.Fields(11).Value, rs.Fields(13).Value), _
    17.                  rs.Fields(6).Value)
    18.     rs.MoveNext
    19. Loop

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2002
    Location
    Newcastle
    Posts
    19

    Open Schema column

    Its nearly there all i want to do is display column names from a table selected in combo1 but all column names form data base are shown in combo 2. I cant think how to do this any ideas are welcome or could some one point me in the right direction thanx
    VB CODE
    _______________________________________________

    'Add all the table names
    Set rstSchema = cnn1.OpenSchema(adSchemaTables)
    Do Until rstSchema.EOF
    Combo1.AddItem rstSchema!TABLE_NAME
    rstSchema.MoveNext
    Loop
    rstSchema.Close

    'Add all the column names
    Set rstSchema = cnn1.OpenSchema(adSchemaColumns)
    Do Until rstSchema.EOF
    Combo2.AddItem rstSchema!COLUMN_NAME
    rstSchema.MoveNext
    Loop
    rstSchema.Close
    cnn1.Close
    ___________________________________________________
    END CODE
    david

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    You did not set any criterias. fungi showed a sample with

    Set rs = conn.OpenSchema(adSchemaColumns, Array(Empty, Empty, rsTables(TABLE_NAME)))

    In your case

    Set rstSchema = cnn1.OpenSchema(adSchemaColumns, Array(Empty,Empty, Combo1.Text) )

    Put the code to load combo2 in the click event of Combo1.

  5. #5
    Frenzied Member andreys's Avatar
    Join Date
    Sep 2002
    Location
    Los Angeles
    Posts
    1,615
    OR...

    you could use recordset to to show all fields

    Code:
    set rs=CreateObject("ADODB.Recordset")
    rs.cursorlocation=adUseClient
    rs.open "SELECT * FROM [" & Combo1.Text & "]", conn
    
    for i=0 to rs.fields.count-1
       Combo2.AddItem rs.fields(i).name
    next i
    
    rs.close
    set rs=nothing

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