Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I'm trying to store a recordset in a multi-dimensional array in javascript, this is my current code:

JavaScript
var cn = new ActiveXObject("ADODB.Connection");
var strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\\BoMQuizWebAppv1.1\\BookOfMormonQuiz.mdb;"

cn.Open(strConn);

var rs = new ActiveXObject("ADODB.Recordset");
var sql = "SELECT * FROM Questions;"

rs.Open(sql,cn);

var count = new ActiveXObject("ADODB.Recordset");
sql = "SELECT COUNT(*) FROM Questions;"

count.Open(sql,cn);

var total = count(0);

questions = new Array(total);
	
for (i = 0; i < total - 1; i++) {
	questions[i] = new Array(10);	
}

for (i = 0; i < total - 1; i++) {
   for (j = 0; j < 10; j++) {
      questions[i][j] = rs(j);
   }
}


I've been in this thing for hours, I'm driving crazy!!!
Can someone help me, Please?
Posted
Updated 19-Aug-14 9:46am
v2
Comments
Sergey Alexandrovich Kryukov 19-Aug-14 16:32pm    
Why doing that in Javascript? What do you mean by "ASP"? Are you really using "ASP" (quite obsolete stuff), not ASP.NET?
—SA
FranciscoXCosta 19-Aug-14 16:41pm    
Yes I'm using classic "ASP", yes it might be obsolete but I have no idea how to work with ASP.NET with so little time I have.
What other language do you have in mind if not javascript, just notice that I'm a novice here!!!

1 solution

Please try the code below. I have used a table named cstate as a sample kindly replace it with your own table name.
XML
<%
dim con, opt
set con = server.createobject("adodb.connection")
con.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = c:\\BoMQuizWebAppv1.1\\BookOfMormonQuiz.mdb;"
set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 3
rs.open "select * from cstate", con
%>
<script language="javascript">
rowCount = "<%=rs.recordcount%>"
colCount = "<%=rs.fields.count%>"
var states = new Array(<%=rs.recordcount%>)
alert(states.length);
for(i = 0; i < states.length; i++)
{
    states[i] = new Array(<%=rs.fields.count%>)
}
<%
    i = 0

    while (not rs.eof)
        j = 0
        for each k in rs.fields
        %>
        states[<%=i%>][<%=j%>] = "<%=k.value%>"
        <%
            j = j + 1
        next
        i = i + 1
        rs.movenext
    wend
%>
for(i = 0; i < states.length; i++)
{
    for(j = 0; j < states[i].length; j++)
    {
        document.write(states[i][j]);
    }
}

</script>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900