Display query results into HTML using ASP

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.
sl1ngerAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
m8rixConnect With a Mentor Commented:
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
 
gladxmlCommented:
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
 
casstdCommented:
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
sl1ngerAuthor Commented:
How can I add a row count?  If possible, I'd like to display the number of results; w/out writing another query.
0
 
sl1ngerAuthor Commented:
I'd also like to alternate colors between each row. White, grey, white, grey, etc.
0
 
m8rixCommented:
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
All Courses

From novice to tech pro — start learning today.