SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    [SQL] Display Column Names from a Table

    Anyone know how to retrieve to column names from a table? I've seen it done before but cant remember what the syntax is.


    Thanks in advance!

  2. #2
    SitePoint Zealot oodie's Avatar
    Join Date
    Jul 2000
    Location
    Misty Mountain
    Posts
    125
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SHOW COLUMNS FROM tablename

  3. #3
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I cant seem to get it to work on my ASP Page..

    Can someone post an example of how you output this to the page. The ultimate goal is to make the display the column names as checkboxes.

  4. #4
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try the following links moospot:

    http://www.4guysfromrolla.com/webtech/090899-1.shtml
    http://www.4guysfromrolla.com/webtech/101799-1.shtml

    If you're not using SQL Server check the second link.

    With SQL Server the query to get the column names for a particular table is as follows. You could just use the query to return a RS and use that to display the col names.
    Code:
    SELECT 	[name] AS [Column name]
    FROM 	syscolumns
    WHERE 	id = (SELECT id 
    		FROM sysobjects
    		WHERE type = 'U'
    		AND [NAME] = <table name>)

  5. #5
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I guess I should have mentioned that. I am using SQL Server 7. I was using a FOR loop with the following syntax:

    <%do until rs.EOF%>
    <tr>
    <%for each x in rs.Fields%>
    <td><%Response.Write(x.name)%></td>
    <%next
    rs.MoveNext%>
    </tr>
    <%loop
    rs.close
    conn.close
    %>

    I get the names , but it repeats for each record. If I drop the rs.MoveNext, maybe.... hmm let me try that

  6. #6
    Xbox why have you forsaken me? moospot's Avatar
    Join Date
    Feb 2001
    Location
    Clearwater, FL
    Posts
    3,615
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I'm starting to feel really stupid



    OKay ..I finally got it!

    <%
    rs.MoveFirst
    for each x in rs.Fields
    %>

    HTML CODE HERE

    <%
    next
    rs.close
    %>


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
  •