Advertisement
6_2008-2009 String Manipulation #207199

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.

AI

Shrnutí AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Zdrojový kód
original-source
<%
' ----------------------------------------------------------------------------
' 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>","&nbsp;") 
	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))
%>
Původní komentáře (3)
Obnoveno z Wayback Machine