如何在javascript多维数组中存储asp记录集?

时间:2014-08-19 19:51:55

标签: javascript arrays asp-classic

我试图在javascript中将记录集存储在多维数组中,这是我目前的代码:

<%
var cn = new ActiveXObject("ADODB.Connection");
var strConn ="Provider=Microsoft.Jet.OLEDB.4.0;DataSource=(...).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);
   }
}
%>

我已尝试使用.GetRows()。 我使用配置为运行javascript的IIS。 我已经在这里待了几个小时,我开车疯了! 有人可以帮助我吗?

1 个答案:

答案 0 :(得分:4)

您可以随时在同一页面中混合使用VBS和JS,例如

<%@LANGUAGE="Javascript" CODEPAGE="65001"%>

<script language="VBScript" runat="server">    
Set cn = Server.CreateObject("ADODB.Connection")

cn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.Mappath("../pathto/yourdb.mdb") 
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "SELECT * FROM Questions"

rs.Open sql,cn,3,1

Set count =  Server.CreateObject("ADODB.Recordset")
sql = "SELECT COUNT(*) FROM Questions"

count.Open sql,cn,3,1

total = count(0)
</script>

<%
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);
   }
}
%>