Convert SQL To HTML Table
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.
Original Author: Ron de Frates
Inputs
SQL query
Assumptions
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.
Returns
A string containing the results as a HTML table
Code
Loading Comments ... No comments have been added for this post. You must be logged in to make a comment.<%
' ----------------------------------------------------------------------------
' 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(,,""," "," ")
sHTMLTbl = Mid(sHTMLTbl, 1, Len(sHTMLTbl) - 8)
sHTMLTbl = "
" " & sHTMLTbl & "
cnvrtRSToHTML = sHTMLTbl
End Function
' -----------------------------------------------------------------------------
' ***** HOW TO CALL THIS FUNCTION *****
Dim sSQL
sSQL = "SELECT * FROM myTable "
Response.Write(cnvrtRSToHTML(sSQL))
%>
Comments