Web development India freelance website designer developer India SEO

{\rtf1\ansi\ansicpg1252\deff0\deflang1044{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
\viewkind4\uc1\pard\f0\fs20 Display the results of an ADO recordset in a HTML table\fs17
\par
\par Option Explicit
\par
\par The following example function can be used on an ASP page to display the results of an ADO recordset in HTML.
\par
\par <%
\par 'Purpose : Outputs the result of a recordset to a table
\par 'Inputs : oRs The opened recordset containing the rows to display
\par ' sTitle The title of the table, if Empty then no title is printed.
\par ' lWidth The width of the table in percent, if Empty the 100% is used.
\par ' lBorder The table border, if Empty the 1 is used.
\par ' lDateFormat The date format for any date values found in the recordset,
\par ' if Empty the vbLongDate is used.
\par ' sHideCols A comma seperated string containing a list of the columns to hide,
\par ' if Empty all columns in the recordset are visible,
\par ' eg "1,2" would hide the 2nd and 3rd columns.
\par ' lAnchorCol The index of the column within the HTML table to contain an anchor tag.
\par ' If empty no anchors are added.
\par ' sAnchorText The static anchor text used in the column specified by lAnchorCol.
\par ' eg. could be "http://www.MyWebSite/GetThisArticle.asp?ArticleID="
\par ' or "mailto:"
\par ' lAnchorParamCol The number of the column in the recordset which contains the anchor text to append to
\par ' sAnchorText.
\par ' eg. would be the column in the recordset containing the ArticleID for the above example.
\par ' or would be the column contains the email address for the "mailto:" text.
\par 'Outputs : Returns -1 on failure else returns the number of rows in the table.
\par 'Author : Andrew Baker
\par 'Date : 8/Aug/2001
\par 'Notes :
\par
\par Function RStoTable(oRS, sTitle, lWidth, lBorder, lDateFormat, sHideCols, lAnchorCol, sAnchorPage, lAnchorParamCol)
\par Dim lNumRows, lNumCols, avResults
\par Dim lThisCol, lThisRow
\par
\par 'on error resume next
\par 'Set up default parameters
\par If IsNumeric(lWidth) = False Then
\par lWidth = 100
\par End If
\par If IsNumeric(lBorder) = False Then
\par lBorder = 1
\par End If
\par If IsNumeric(lDateFormat) = False Then
\par lDateFormat = vbLongDate
\par End If
\par
\par 'Get results into array
\par If oRst.EOF = False Then
\par avResults = oRst.GetRows(-1)
\par lNumRows = UBound(avResults, 2) + 1
\par lNumCols = UBound(avResults, 1) + 1
\par RStoTable = lNumRows
\par Else
\par 'Return success code
\par RStoTable = -1
\par Exit Function
\par End If
\par
\par If Len(sHideCols) Then
\par 'Format the comma seperated string
\par 'containing the columns to hide
\par If Left(sHideCols, 1) <> "," Then
\par sHideCols = "," & sHideCols
\par End If
\par If Right(sHideCols, 1) <> "," Then
\par sHideCols = sHideCols & ","
\par End If
\par sHideCols = Replace(sHideCols, " ", "")
\par End If
\par
\par If Len(lAnchorCol) = 0 Then
\par lAnchorCol = -1
\par End If
\par
\par 'Display header
\par Response.Write "
"
\par If Len(sTitle) Then
\par 'Display title
\par Response.Write ""
\par End If
\par
\par 'Display results
\par For lThisRow = -1 To lNumRows - 1
\par Response.Write ""
\par For lThisCol = 0 To lNumCols - 1
\par If InStr(1, sHideCols, "," & lThisCol & ",") = 0 Then
\par 'Display this column
\par If lThisRow = -1 Then
\par 'Write column header
\par Response.Write "" & vbNewLine
\par Else
\par 'Write row results
\par If oRst.Fields(lThisCol).Type = 7 Then
\par If lAnchorCol = lThisCol Then
\par 'Write date anchor row
\par Response.Write "" & vbNewLine
\par Else
\par 'Write a date row
\par Response.Write "" & vbNewLine
\par End If
\par Else
\par If lAnchorCol = lThisCol Then
\par 'Write anchor row
\par Response.Write "" & vbNewLine
\par Else
\par 'Write row
\par If IsNull(avResults(lThisCol, lThisRow)) = True Or Len(Trim(avResults(lThisCol, lThisRow))) = 0 Then
\par 'Write empty cell
\par Response.Write "" & vbNewLine
\par Else
\par 'Write normal cell
\par Response.Write "" & vbNewLine
\par End If
\par End If
\par End If
\par End If
\par End If
\par Next
\par Response.Write ""
\par Next
\par Response.Write "

" & sTitle & "

" & oRst.Fields(lThisCol).Name & "" & FormatDateTime(avResults(lThisCol, lThisRow), lDateFormat) & "" & FormatDateTime(avResults(lThisCol, lThisRow), lDateFormat) & "" & avResults(lThisCol, lThisRow) & " " & Replace(avResults(lThisCol, lThisRow), vbNewLine, "
") & "
"
\par
\par 'Close Recordset
\par oRS.Close
\par
\par If Err.Number Then
\par 'Return failure code
\par RStoTable = -1
\par Response.Write "Failed to output recordset results: " & Err.Description
\par End If
\par End Function
\par
\par
\par 'Example usage:
\par 'Connect to Database
\par sMappedPath = Server.MapPath("\\mydb.mdb")
\par Set oCon = Server.CreateObject("adodb.connection")
\par oCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sMappedPath & "; Persist Security Info=False"
\par
\par 'Open recordset
\par Set oRst = Server.CreateObject("adodb.recordset")
\par oRst.Open "Select * from qryStats", oCon, adOpenForwardOnly
\par
\par 'Center the table on the page
\par Response.Write "

"
\par 'Display results
\par RStoTable oRst, "Summary Statistics Table", 50, 1, vbLongDate
\par Response.Write "

"
\par
\par 'Close recordset
\par Set oRst = Nothing
\par oCon.Close
\par Set oCon = Nothing
\par %>
\par }
Display the results of an ADO recordset 2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150

India web developer web development India | India web development company India ecommerce web developer