Solved

Display query results into HTML using ASP

Posted on 2004-10-25
271 Views
Last Modified: 2008-03-17
I have an ASP page and would like the query result to display in html
my example:

dim sSQL, adoRS

sSQL = "Select UserID, UserName, UserEmail from tbl Users"

Do Until adoRS.EOF
  iSource = 0
      Do Until iSource = (adoRS.Fields.Count)
         response.write "<td>" &UserID & "</td>"
         response.write "<td>" & UserName & "</td>"
         response.write "<td>" & UserEmail & "</td>"
         iSource = iSource + 1
   Loop
   adoRS.MoveNext
Loop
adoRS.close

How should I do this??  Any help appreciated.. Thanks in Advance.
0
Question by:sl1nger
    6 Comments
     
    LVL 10

    Accepted Solution

    by:
    Hi sl1nger! Is this what you mean?

    dim sSQL, adoRS

    sSQL = "Select UserID, UserName, UserEmail from tbl Users"

    response.write "<table>"
    Do Until adoRS.EOF
       response.write "<tr>"  
       response.write "<td>" & adoRS("UserID") & "</td>"
       response.write "<td>" & adoRS("UserName") & "</td>"
       response.write "<td>" & adoRS("UserEmail") & "</td>"
       response.write "</tr>"
       adoRS.MoveNext
    Loop
    response.write "</table>"
    adoRS.close
    0
     
    LVL 15

    Expert Comment

    by:gladxml
    you can also try this...

    ===
    <%
    dim sSQL, adoRS
    set adoRS=Server.CreateObject("ADODB.recordset")
    sSQL = "Select UserID, UserName, UserEmail from tbl Users"
    'assuming that your connection object is conn then
    rs.Open sql, conn
    %>
    <table>
    <%
    if not(adoRS.EOF) then
    Do while not(adoRS.EOF)%>
      <tr>  
       <td><%=adoRS("UserID")%></td>
       <td><%=adoRS("UserName")%></td>
      <td><%=adoRS("UserEmail")%></td>
       </tr>
       <%adoRS.MoveNext
    Loop
    end if
    adoRS.close%>
    </table>

    ===

    You can also look at the link below might help...

    http://www.w3schools.com/ado/ado_query.asp

    HTH...

    Happy programming...

    0
     
    LVL 6

    Expert Comment

    by:casstd
    Hi,

             This is another way of displaying with the Table Headings.

    Response.write "<table border=1 cellspacing=1 cellpadding=1>"
    Response.write "<TR>"
    Response.write "<td valign=top>No</TD>"
    Response.write "<td valign=top>UserID</TD>"
    Response.write "<td valign=top>User Name</TD>"
    Response.write "<td valign=top>Email</TD>"
    Response.write "</tr>"

    dim sSQL, adoRS
    iSource = 0
    sSQL = "Select UserID, UserName, UserEmail from tbl Users"
    set adoRS = Dbobj.execute(ssql)

    if not adoRS.EOF then
      Do Until adoRS.EOF
           iSource = iSource + 1
             Response.write "<TR>"
             response.write "<td>" &iSource& "</td>"
             response.write "<td>" &adoRS("UserID")& "</td>"
             response.write "<td>" & adoRS("UserName")&  "</td>"
             response.write "<td>" & adoRS("UserEmail")&  "</td>"
             Response.write "</tr>"
             adoRS.MoveNext
       Loop
    end if

    Response.write "</table>"
    adoRS.close

    Hope this would be Helpful to you.

    0
     

    Author Comment

    by:sl1nger
    How can I add a row count?  If possible, I'd like to display the number of results; w/out writing another query.
    0
     

    Author Comment

    by:sl1nger
    I'd also like to alternate colors between each row. White, grey, white, grey, etc.
    0
     
    LVL 10

    Expert Comment

    by:m8rix
    Hi sl1nger, thanks for the points!

    The following code will answer your additional questions.

    Reg's
    m8rix

    <%
    dim sSQL, adoRS

    sSQL = "Select UserID, UserName, UserEmail from tbl Users"
    BackColor = "#FFFFFF"
    Counter = 0

    response.write "<table>"
    Do Until adoRS.EOF
       Counter = Counter + 1
       if BackColor = "#FFFFFF" then
          BackColor = "#FBFBFB"
       Else
          BackColor = "#FFFFFF"
       End if
       response.write "<tr style=""background-color: " & BackColor & """>"  
       response.write "<td>" & Counter & "</td>"
       response.write "<td>" & adoRS("UserID") & "</td>"
       response.write "<td>" & adoRS("UserName") & "</td>"
       response.write "<td>" & adoRS("UserEmail") & "</td>"
       response.write "</tr>"
       adoRS.MoveNext
    Loop
    response.write "</table>"
    adoRS.close
    %>
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Learn The Basics of Ethical Hacking & Pen Testing

    Computer and network security is one of the fastest growing and most essential industries in technology, meaning companies will pay big bucks for ethical hackers. This is the perfect course to leap into this lucrative career, learning how to use ethical hacking to reveal ...

    Suggested Solutions

    I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
    This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
    This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
    This video discusses moving either the default database or any database to a new volume.

    856 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now