www.webdeveloper.com
Results 1 to 4 of 4

Thread: ASP display * from table

  1. #1
    Join Date
    Jul 2006
    Posts
    146

    ASP display * from table

    Hi,

    I am kind of new to asp, but experienced with PHP and .net .

    I am doing some reverse engineering of a site, I have the server connection info, and think that I have a table that I am interested in.

    I could create a recordset connected to the sql ("select * from thisTable") but I don't know the corresponding field names (that is what I want to know).

    Anyone able to tell me where to go on this? probably pretty easy...

    Thanks very much,

  2. #2
    Join Date
    Mar 2006
    Posts
    591
    If I'm correct you only want to know the column names in a table?

  3. #3
    Ubik's Avatar
    Ubik is offline <%= "New Meja Hor" %>
    Join Date
    Nov 2005
    Location
    Earth
    Posts
    361
    PHP Code:
    dim aMyRecordSetboolSuccess
    aMyRecordSet 
    aGetRecords ("SELECT * from TABLE;")
    boolSuccess Dump2dArray(aMyRecordSet)

    function 
    Dump2dArray(aMyRecordSet)
        
    dim intTotalRowCountintTotalColCountintColCounterintRowcounter
        intTotalRowCount 
    ubound(aMyRecordSet,2)
        
    intTotalColCount ubound(aMyRecordSet,1)
        
    response.write "<ol>"
        
    FOR intRowcounter 0 TO intTotalRowCount 
            response
    .write "<li><ul>"
            
    FOR intColCounter 0 TO intTotalColCount 
                response
    .write "<li>"&aMyRecordSet(intColCounterintRowcounter)&"</li>"
            
    NEXT
        response
    .write "</ul></li>"
        
    NEXT
        response
    .write "</ol>"
    end function

    function 
    aGetRecords (strSQL)
     
    dim connrs
     Set conn 
    Server.CreateObject("ADODB.Connection")
     
    conn.open YOURDSNHERE
     Set rs 
    Server.CreateObject("ADODB.Recordset")
     
    rs.open strSQLconn
     
    if not rs.BOF and not rs.EOF then
      aGetRecords 
    rs.GetRows
     
    else
      
    aGetRecords=""
     
    end if
     
    rs.close
     conn
    .close
     Set rs 
    Nothing
     Set conn 
    Nothing
    end 
    function 

  4. #4
    Join Date
    Dec 2003
    Location
    England, UK
    Posts
    432
    there is a fields collection on the recordset object you can use to get the names.

    so you can use

    for i = 0 to rs.fields.length - 1
    response.write "<br>" & rs.fields(i).name
    next

    i think. (might not be perfect, i just wrote it from memory).

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles