Simple Function To Return Recordset Results as Table In HTML


/ Published in: ASP
Save to your folder(s)

A quick and easy function that will output table column names and loop through your SQL recordset results outputting it into a HTML table.


Copy this code and paste it in your HTML
  1. function ReturnHTMLTable(query)
  2.  
  3. set rs = cn.Execute(query)
  4.  
  5. rs.MoveFirst
  6. response.Write "<table class=""data"" cols=""" & rs.Fields.Count & """>"
  7. response.Write "<tr>"
  8.  
  9. For Each oField In rs.Fields
  10. response.Write "<th>" & oField.Name & "</th>"
  11. Next
  12.  
  13. response.Write "</tr>"
  14.  
  15. Do While Not rs.EOF
  16.  
  17. response.Write "<tr>"
  18.  
  19. For Each oField In rs.Fields
  20.  
  21. response.Write "<td>"
  22.  
  23. If IsNull(oField) Then
  24. response.Write " "
  25. Else
  26. response.Write oField.Value
  27. End If
  28.  
  29. response.Write "</td>"
  30.  
  31. Next
  32. rs.MoveNext
  33.  
  34. response.Write "</tr>"
  35.  
  36. Loop
  37.  
  38. response.Write "</table>"
  39.  
  40. end function

URL: http://www.nealgrosskopf.com/tech/thread.asp?pid=40

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.