:: Home >>

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

13 Dec 07
Having Problem posting data from a service Ghalib (2)
21 Jun 07
Simple ASP/ADODB.Recordset example Alex (ActiveWidgets) (8)
19 Sep 06
[no subject] (0)

Comments will appear on this page and in the main forum.

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