README.md
December 4, 2022 ยท View on GitHub
Description
Returns the results of a SQL query as an HTML table. This small function is not only very fast it also simplifies the programming logic for displaying data.
More Info
SQL query
Requires ADO 2.0 or higher. I benchmarked this code against a traditional "rs.MoveNext" method and got a 100% speed improvement for 200 records.
A string containing the results as a HTML table
| Submitted On | |
| By | Ron de Frates |
| Level | Beginner |
| User Rating | 5.0 (15 globes from 3 users) |
| Compatibility | ASP (Active Server Pages) |
| Category | Databases |
| World | ASP / VbScript |
| Archive File |
Source Code
<%
' ----------------------------------------------------------------------------
' NAME: cnvrtRSToHTML
' AUTHOR: Ron de Frates
' DATE: 01/21/2002
' PURPOSE: Converts recordset results to HTML table
' LANGUAGE: ASP, HTML
' OBJECTS: ADODB.Connection
' DATABASES: DSN_Admin
' ----------------------------------------------------------------------------
Function cnvrtRSToHTML(sSQL)
Dim dbConn, rsSrc, sHTMLTbl
Set dbConn = Server.CreateObject("ADODB.Connection")
dbConn.Open
Set rsSrc = dbConn.Execute(sSQL)
sHTMLTbl = rsSrc.GetString(,,"</td><td>","</td></tr><tr><td>"," ")
sHTMLTbl = Mid(sHTMLTbl, 1, Len(sHTMLTbl) - 8)
sHTMLTbl = "<table border=1><tr><td>" & sHTMLTbl & "</table>"
cnvrtRSToHTML = sHTMLTbl
End Function
' -----------------------------------------------------------------------------
' ***** HOW TO CALL THIS FUNCTION *****
Dim sSQL
sSQL = "SELECT * FROM myTable "
Response.Write(cnvrtRSToHTML(sSQL))
%>