472,096 Members | 1,304 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,096 software developers and data experts.

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 1061
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
  3. query = "SELECT * FROM " & request("tableDropDown")
  4. 'get every field from the table specified in the dropdown
  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
  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"
  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>"
  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?

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 leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.