js已连接上sqlserver,怎么取表里的字段值存为数组
1个回答
展开全部
Javascript代码 收藏代码
<script language="javascript">
var conn = new ActiveXObject("ADODB.Connection");
conn.Open("Provider=SQLOLEDB.1; Data Source=tgf; User ID=sa; "
+"Password=sasa; Initial Catalog=MyBulletin");
var rs = new ActiveXObject("ADODB.Recordset");
var sql="select id,name from Category";
rs.open(sql, conn);
alert(rs(0));//取出第一个来
rs.close();
rs = null;
conn.close();
conn = null;
</script>
//连接ACCESS
<script language="javascript">
var array=new Array();//声明数组
function conn(){
var db_bbs
db_bbs="dd.mdb"//定义数据库
var conn = new ActiveXObject("ADODB.Connection");
conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+db_bbs+"");
var rs = new ActiveXObject("ADODB.Recordset");
var sql="select name from authors"; //数据库中有authors表,name字段
rs.open(sql,conn);
alert(rs(0))//取出第一个来
for(var i=0;i<rs.length;i++)
{
array.push(rs(i));//存入数组
}
conn.close();
conn = null;
}
</script>
<script language="javascript">
var conn = new ActiveXObject("ADODB.Connection");
conn.Open("Provider=SQLOLEDB.1; Data Source=tgf; User ID=sa; "
+"Password=sasa; Initial Catalog=MyBulletin");
var rs = new ActiveXObject("ADODB.Recordset");
var sql="select id,name from Category";
rs.open(sql, conn);
alert(rs(0));//取出第一个来
rs.close();
rs = null;
conn.close();
conn = null;
</script>
//连接ACCESS
<script language="javascript">
var array=new Array();//声明数组
function conn(){
var db_bbs
db_bbs="dd.mdb"//定义数据库
var conn = new ActiveXObject("ADODB.Connection");
conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+db_bbs+"");
var rs = new ActiveXObject("ADODB.Recordset");
var sql="select name from authors"; //数据库中有authors表,name字段
rs.open(sql,conn);
alert(rs(0))//取出第一个来
for(var i=0;i<rs.length;i++)
{
array.push(rs(i));//存入数组
}
conn.close();
conn = null;
}
</script>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询