如何在 asp.net 中获取数组中的值(或者 asp-classic 会更好)
How to get value in array in asp.net ( or asp-classic would be better)
我需要使用 asp 在 javascript 数组中获取数据。如何获取数据并将其以这种格式放入 javascript 数组中。这个例子是 php .
<script>var chartdata=[{"values":[<?php $conn =mysql_connect("host","root","pass") or die ("we couldn't connect!");mysql_select_db("test");$rs = mysql_query("SELECT x1 FROM table") or die(mysql_error());while($row = mysql_fetch_array($rs)){echo $row['x'].',';}?>],}];</script>
我假设您了解 adodb 连接和记录集对象(如果您不了解,那里有很多教程),并且您已经创建了一个名为 conn
和 rs
.
在经典中ASP我会做这样的事情
<% Dim myarraystring, sql
sql = "SELECT x1 FROM table"
myarraystring = ""
rs.open sql,conn
Do While Not rs.eof
myarraystring = myarraystring & rs("x") & ","
rs.movenext
Loop
rs.close %>
<script>var chartdata=[{"values":[<%= myarraystring %>],}];</script>
您的连接字符串取决于您使用的驱动程序。这里有一个很好的资源,可以使用经典 asp 连接到 MySQL
http://www.connectionstrings.com/mysql/
我需要使用 asp 在 javascript 数组中获取数据。如何获取数据并将其以这种格式放入 javascript 数组中。这个例子是 php .
<script>var chartdata=[{"values":[<?php $conn =mysql_connect("host","root","pass") or die ("we couldn't connect!");mysql_select_db("test");$rs = mysql_query("SELECT x1 FROM table") or die(mysql_error());while($row = mysql_fetch_array($rs)){echo $row['x'].',';}?>],}];</script>
我假设您了解 adodb 连接和记录集对象(如果您不了解,那里有很多教程),并且您已经创建了一个名为 conn
和 rs
.
在经典中ASP我会做这样的事情
<% Dim myarraystring, sql
sql = "SELECT x1 FROM table"
myarraystring = ""
rs.open sql,conn
Do While Not rs.eof
myarraystring = myarraystring & rs("x") & ","
rs.movenext
Loop
rs.close %>
<script>var chartdata=[{"values":[<%= myarraystring %>],}];</script>
您的连接字符串取决于您使用的驱动程序。这里有一个很好的资源,可以使用经典 asp 连接到 MySQL http://www.connectionstrings.com/mysql/