Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
<%
'Function to convert an ADO recordset into a JSON object
'
'Written by Tracy Dryden, Commonwealth Technology Group, Inc.
'
'Released to the public domain.
function RStoJSON(rs)
dim sFld
dim sFlds
dim sRec
dim sRecs
dim sRecordSet
dim lRecCnt
sRecordSet = ""
sRecs = ""
lRecCnt = 0
if rs.EOF or rs.BOF then
RStoJSON = "null"
else
do while not rs.EOF and not rs.BOF
lRecCnt = lRecCnt + 1
sFlds = ""
for each fld in rs.Fields
sFld = """" & fld.Name & """:""" & toUnicode(fld.Value&"") & """"
sFlds = sFlds & iif(sFlds <> "", ",", "") & sFld
next 'fld
sRec = "{" & sFlds & "}"
sRecs = sRecs & iif(sRecs <> "", "," & vbCrLf, "") & sRec
rs.MoveNext
loop
sRecordSet = "( {""Records"": [" & vbCrLf & sRecs & vbCrLf & "], "
sRecordSet = sRecordSet & """RecordCount"":""" & lRecCnt & """ } )"
RStoJSON = sRecordSet
end if
end function
function toUnicode(str)
dim x
dim uStr
dim uChr
dim uChrCode
uStr = ""
for x = 1 to len(str)
uChr = mid(str,x,1)
uChrCode = asc(uChr)
if uChrCode = 8 then ' backspace
uChr = "\b"
elseif uChrCode = 9 then ' tab
uChr = "\t"
elseif uChrCode = 10 then ' line feed
uChr = "\n"
elseif uChrCode = 12 then ' formfeed
uChr = "\f"
elseif uChrCode = 13 then ' carriage return
uChr = "\r"
elseif uChrCode = 34 then ' quote
uChr = "\"""
elseif uChrCode = 39 then ' apostrophe
uChr = "\'"
elseif uChrCode = 92 then ' backslash
uChr = "\\"
elseif uChrCode < 32 or uChrCode > 127 then ' non-ascii characters
uChr = "\u" & right("0000" & CStr(uChrCode),4)
end if
uStr = uStr & uChr
next
toUnicode = uStr
end function
function iif(cond,tv,fv)
if cond then
iif = tv
else
iif = fv
end if
end function
%>
set cn = Server.CreateObject("ADODB.Connection")
cn.Open "..."
sSQL = "select * from users order by lastname, firstname"
set rs = cn.Execute(sSQL)
response.write RStoJSON(rs)
response.flush
rs.Close
set rs = nothing
cn.close
set cn = nothing
%>
// create the recordset object
var rs = eval(request.responseText);
if ( rs ) { // has a non-null value
// get the record count
var str = rs.RecordCount + " Users:<br/>";
// get the data from the records
for ( var recno = 0 ; recno < rs.RecordCount ; recno++ ) {
str += " ";
str += rs.Records[recno].handle + " is ";
str += rs.Records[recno].firstname + " ";
str += rs.Records[recno].lastname + "<br/>";
}
document.getElementById('userlist').innerHTML = str;
} else { // rs = null
str = "No users found"
}