ASP SQL Table - Need Help!!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • antiredcap
    New Member
    • Sep 2007
    • 3

    #1

    ASP SQL Table - Need Help!!!

    I need to display a sql table on a asp page with a dropdown list.
    The dropdown needs to be connected to SQL, when a table name gets selected from the dropdown the whole table needs to be displayed on the ap page.
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    This is actually very easy, except possibly the dropdown list part. Anyone else know how to populate the dropdown list with every table name in a db?

    the rest of it looks like this: [code=asp]dim conn, rs, query, x

    query = "SELECT * FROM " & request("tableD ropDown")
    'get every field from the table specified in the dropdown

    set conn = server.createOb ject("adodb.con nection")
    conn.open "myDSN1" 'this should be your system DSN for this db, or if you
    'don't use a DSN, you can modify this line to include the path to the db file

    set rs = server.createOb ject("adodb.rec ordet")
    rs.open query, conn
    'populates the recordset "rs" from the data specified in "query" using the
    ' connection specified in "conn"

    'make a header row in the table
    response.write "<table><tr >"
    for each x in rs.fields
    response.write "<th>" & x.name & "</th>" & vbNewLine
    next
    response.write "</tr>"

    'the body of the table is the actual data
    do until rs.eof 'keep going until we get to the end of the recordset
    response.write "<tr>" 'each record makes up one table row
    for each x in rs.fields
    response.write "<td>" & x.value & "</td>" & vbNewLine
    'the value in each field makes up the values in each cell of the table
    next
    response.write "</tr>"
    rs.movenext 'go to the next record
    loop
    response.write "</table>"[/code] Normally I try not to give whole code answers since it is important for the askers to work out how to solve problems, but this was an approach that really changed my perspective and simplified how I displayed tables. Does everything make sense?

    Jared

    Comment

    • antiredcap
      New Member
      • Sep 2007
      • 3

      #3
      Yes... thanks a lot!!

      Comment

      Working...