469,317 Members | 1,851 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,317 developers. It's quick & easy.

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.
Sep 18 '07 #1
2 1026
jhardman
3,406 Expert 2GB
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:
Expand|Select|Wrap|Line Numbers
  1. dim conn, rs, query, x
  2.  
  3. query = "SELECT * FROM " & request("tableDropDown")
  4. 'get every field from the table specified in the dropdown
  5.  
  6. set conn = server.createObject("adodb.connection")
  7. conn.open "myDSN1" 'this should be your system DSN for this db, or if you
  8.    'don't use a DSN, you can modify this line to include the path to the db file
  9.  
  10. set rs = server.createObject("adodb.recordet")
  11. rs.open query, conn
  12. 'populates the recordset "rs" from the data specified in "query" using the
  13. ' connection specified in "conn"
  14.  
  15. 'make a header row in the table
  16. response.write "<table><tr>"
  17. for each x in rs.fields
  18.    response.write "<th>" & x.name & "</th>" & vbNewLine
  19. next
  20. response.write "</tr>"
  21.  
  22. 'the body of the table is the actual data
  23. do until rs.eof 'keep going until we get to the end of the recordset
  24.    response.write "<tr>" 'each record makes up one table row
  25.    for each x in rs.fields
  26.       response.write "<td>" & x.value & "</td>" & vbNewLine
  27.       'the value in each field makes up the values in each cell of the table
  28.    next
  29.    response.write "</tr>"
  30.    rs.movenext 'go to the next record
  31. loop
  32. response.write "</table>"
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
Sep 18 '07 #2
Yes... thanks a lot!!
Sep 20 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

9 posts views Thread by netpurpose | last post: by
9 posts views Thread by Tony Girgenti | last post: by
13 posts views Thread by PinkBishop | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.