SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: Listing Tables

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    CA, US
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Listing Tables

    I need a way to list all the table names in a database with ASP, I saw it on a web site sometimes ago, but can't find it now. Any one know how?

  2. #2
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why do you want to do this? Explain, there may be a better methodology than getting the field names. Why would you want them?
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    CA, US
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am making a web site. When users signed up, a table is created for the user in our database. I don't REALLY need it, but it would be easier for me to admin the site. I thought I saw the code somewhere, but can't find it now.

  4. #4
    I have an opinion...
    Join Date
    Sep 2001
    Location
    Barrie, Ontario
    Posts
    324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have been working on a dbDocumentor ASP Class that would automatically generate HTML/TXT/XML documentation for any database. When it is finished, I will be posting it with the rest of my open source projects on InteliDev, but I have gotten distracted by work projects. Here are a few functions from that project that may get you going in the right direction. You can see a working demonstration of this exact script at InteliDev Demos.

    Code:
    Public Const dbTables = 20
    Public Const dbColumns = 4
    
    
    '*********************************************************
    '	Opens the specified database
    '*********************************************************
    
    strFile = "demo_3.mdb"
    
    If Not InStr( strFile, ":\" ) Then strFile = Server.MapPath( strFile )
    Set Con = Server.CreateObject( "ADODB.Connection" )
    Con.Open( "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & strFile )
    
    
    '*********************************************************
    '	Columns() returns a list of the table columns
    '*********************************************************
    
    Public Function Columns( strTable )
    	Set Rec = Con.OpenSchema( dbColumns, Array( Empty, Empty,  strTable ) )
    	While Not Rec.EOF
    		strList = strList & Rec( "Column_Name" ) & Chr(44)
    		Rec.MoveNext
    	Wend
    	arrList = Split( Left( strList, Len( strList ) - 1 ), Chr(44) )
    	Rec.Close : Set Rec = Nothing
    	Columns = arrList
    End Function
    
    
    '*********************************************************
    '	Tables() returns a list of the table columns
    '*********************************************************
    
    Public Function Tables()
    	Set Rec = Con.OpenSchema( dbTables, Array( Empty, Empty, Empty, "Table" ) )
    	While Not Rec.EOF
    		strList = strList & Rec( "Table_Name" ) & Chr(44)
    		Rec.MoveNext
    	Wend
    	arrList = Split( Left( strList, Len( strList ) - 1 ), Chr(44) )
    	Rec.Close : Set Rec = Nothing
    	Tables = arrList
    End Function
    
    
    '*********************************************************
    '	Write a basic list to the document
    '*********************************************************
    
    arrTables = Tables()
    For Idx = LBound( arrTables ) To UBound( arrTables )
    	Response.Write( "<ul><b>" & arrTables( Idx ) & "</b><ul>" )
    	arrColumns = Columns( arrTables( Idx ) )
    	For Each Entry In arrColumns
    		Response.Write( "<li>" & Entry & "</li>" )
    	Next
    	Response.Write( "</ul></ul>" )
    Next
    
    
    '*********************************************************
    '	Close the specified database and cleanup objects
    '*********************************************************
    
    If Con.State > 0 Then Con.Close
    If IsObject( Con ) Then Set Con = Nothing
    If IsObject( Rec ) Then Set Rec = Nothing
    Last edited by KodeKrash; Sep 5, 2001 at 01:51.
    Egotist: A person more interested in himself than in me.
    KodeKrash - Eidix - Barrie LUG

  5. #5
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,294
    Mentioned
    123 Post(s)
    Tagged
    1 Thread(s)
    Originally posted by sforn
    I am making a web site. When users signed up, a table is created for the user in our database. I don't REALLY need it, but it would be easier for me to admin the site. I thought I saw the code somewhere, but can't find it now.
    I'm assuming you have a user or member table in the database. Why don't you just add a field in the table which contains the tablename for that user?
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2001
    Location
    CA, US
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, the code works really well


Bookmarks

Posting Permissions

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