Listing E



Function fnSQLtoHTML(sFilePath, sSQL, sElementName)

 Dim sRetVal, oConn, oRS

 Set oConn = Server.CreateObject("ADODB.Connection")

 Set oRS = Server.CreateObject("ADODB.Recordset")

 If sFilePath = "" Then

       sRetVal = "No Database File"

 ElseIf sSQL = "" Then

       sRetVal = "No SQL Statement"

 ElseIf sElementName = "" Then

       sRetVal = "No Element Name"

 Else

       sRetVal = vbCrLf & "<table id='" & sElementName & "' name='" & sElementName & "'>"

       On Error Resume Next

oConn.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(sFilePath))

       If Err.Number = 0 Then

              Set oRS = oConn.Execute(sSQL)

              If Err.Number = 0 Then

                     sRetVal = sRetVal & vbCrLf & "<tr>"

                     For Each Field in oRS.Fields

                           sRetVal = sRetVal & "<th align=left valign=top>" & Field.Name & "</th>"

                     Next

                     sRetVal = sRetVal & "</tr>"

                     Do Until oRS.EOF

                           sRetVal = sRetVal & vbCrLf & "<tr>"

                           For Each Field in oRS.Fields

                           sRetVal = sRetVal & "<td align=left valign=top>" & Field.value & "</td>"

                           Next

                           sRetVal = sRetVal & "</tr>"

                           oRS.MoveNext

                     Loop

              Else

                     sRetVal = sRetVal & vbCrLf & "<tr><td>" & Err.Description & "</td></tr>"

              End If

              oConn.Close

       Else

              sRetVal = sRetVal & "<tr><td>" & Err.Description & "</td></tr>"

       End If

       sRetVal = sRetVal & vbCrLf & "</table>"

 End If

 Set oRS = Nothing

 Set oConn = Nothing

 fnSQLtoHTML = sRetVal


End Function