<script language="javascript">
//用 javascript 写服务器端连接数据库的代码示例
function conn(){
var db_bbs
db_bbs="dd.mdb"//定for义a数s据p库.cn
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))//取出第一个来
conn.close();
conn = null;
}
</script>
以下的是sql连接
<script language="javascript">
//用 JavaScript 写服务器端连接数据库的代码示例 www.forasp.cn 网址制作学习
var conn = new ActiveXObject("ADODB.Connection");
conn.Open("Provider=SQLOLEDB.1; Data Source=localhost; User ID=sa; " +"Password=; Initial Catalog=pubs");
var rs = new ActiveXObject("ADODB.Recordset");
var sql="select * from authors";
rs.open(sql, conn);
rs.close();
rs = null;
conn.close();
conn = null;
</script>
更多信息请查看IT技术专栏