:: Documentation >>

ASP/ADODB recordset

ASP, ADODB, VBScript -

<%@ LANGUAGE = VBScript %>
<%
    Dim oConnection
    Dim oRecordset

    Set oConnection = Server.CreateObject("ADODB.Connection")
    oConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("database.mdb")

    Set oRecordset = oConnection.Execute("SELECT * FROM table")

function aw_string(s)

    s = Replace(s, "\", "\\") 
    s = Replace(s, """", "\""") 'replace javascript control characters - ", \
rem s = Replace(s, vbCr, "\r")
rem s = Replace(s, vbLf, "\n")

    aw_string = """" & s & """"

end function

function aw_headers(oRecordset)

    Dim i, count, headers()

    count = oRecordset.fields.count
    ReDim headers(count-1)

    For i=0 to count-1
        headers(i) = aw_string(oRecordset(i).name)
    Next

    Response.write("[" & Join(headers, ", ") & "];")

end function

function aw_cells(oRecordset)

    Dim i, col_count, row_count, columns(), rows()

    row_count = 0
    col_count = oRecordset.fields.count
    ReDim columns(col_count-1)

    Do while (Not oRecordset.eof)

        For i=0 to col_count-1
            columns(i) = aw_string(oRecordset(i))
        Next

        ReDim preserve rows(row_count)

        rows(row_count) = vbTab & "[" & Join(columns, ", ") & "]"
        row_count = row_count + 1

        oRecordset.MoveNext
    Loop

    Response.write("[" & vbNewLine & Join(rows, "," & vbNewLine) & vbNewLine & "];" & vbNewLine)

end function

%>
<html>
<head>
    <script src="../../runtime/lib/aw.js"></script>
    <link href="../../runtime/styles/xp/aw.css" rel="stylesheet"></link>
</head>
<body>
<style>

</style>
<script>

//    insert javascript arrays produced by ASP functions
    var myHeaders = <%= aw_headers(oRecordset) %>
    var myCells = <%= aw_cells(oRecordset) %>

//    create grid control
    var obj = new AW.UI.Grid;

//    set grid text
    obj.setHeaderText(myHeaders);
    obj.setCellText(myCells);

//    set number of columns/rows
    obj.setColumnCount(myHeaders.length);
    obj.setRowCount(myCells.length);

//    write grid to the page
    document.write(obj);

</script>
</body>
</html>
<%
    oRecordset.close
    oConnection.close
%>

Comments

Having Problem posting data from a service Ghalib (2)
Simple ASP/ADODB.Recordset example Alex (ActiveWidgets) (8)
[no subject] (0)

Documentation:

Recent changes:

2.6.4
2.6.3
2.6.2
2.6.1
2.6.1
2.6.0
2.5.0 - 2.5.6
2.5.6
2.5.0 - 2.5.5
2.5.5