JS操作 Access 数据库 复制代码 代码如下: <br /> <!-- <br /> var filePath = location.href.substring(0, location.href.indexOf("实例197.连接Access数据库.html")); //以当前页面文件为基础,找到文件所在的绝对路径 <br /> var path = filePath + "197.mdb"; <br /> path = path.substring(8); <br /> var objdbConn = new ActiveXObject("ADODB.Connection"); <br /> var strdsn = "driver={Microsoft Access Driver (*.mdb)};dbq=" + path; <br /> objdbConn.Open(strdsn); <br /> document.write("连接ACCESS数据库成功!<br>"); <br /> objdbConn.Close(); <br /> //--> <br /> 连接SQL Server数据库 复制代码 代码如下: <br /> <!-- <br /> var objdbConn = new ActiveXObject("ADODB.Connection"); <br /> var strdsn = "Driver={SQL Server};SERVER=(local);UID=sa;PWD=111111;DATABASE=hljdatabase"; <br /> objdbConn.Open(strdsn); <br /> document.write("数据库连接成功<br>"); <br /> objdbConn.Close(); <br /> //--> <br /> 查询数据库实例 复制代码 代码如下: <br /> <!-- <br /> var objdbConn = new ActiveXObject("ADODB.Connection"); <br /> var strdsn = "Driver={SQL Server};SERVER=(local);UID=sa;PWD=111111;DATABASE=hljdatabase"; // 需要修改自己的服务器地址,用户名,密码 <br /> objdbConn.Open(strdsn); <br /> var objrs = objdbConn.Execute("SELECT * FROM 表 where 关联=0"); // 输入本地的表 <br /> var fdCount = objrs.Fields.Count - 1; <br /> if (!objrs.EOF){ <br /> document.write("<table border=1><tr>"); <br /> for (var i=0; i <= fdCount; i++) <br /> document.write("<td><b>" + objrs.Fields(i).Name + ""); <br /> document.write(""); <br /> <br /> while (!objrs.EOF){ <br /> document.write("<tr>"); <br /> for (i=0; i <= fdCount; i++) <br /> document.write("<td valign='top'>" + objrs.Fields(i).Value + ""); <br /> document.write(""); <br /> objrs.moveNext(); <br /> } <br /> document.write(""); <br /> } <br /> else <br /> document.write("数据库内没有记录!<br>"); <br /> objrs.Close(); <br /> objdbConn.Close(); <br /> //--> <br /> 操作数据库实例 复制代码 代码如下: <br /> <!-- <br /> var objdbConn = new ActiveXObject("ADODB.Connection"); <br /> var strdsn = "Driver={SQL Server};SERVER=(local);UID=sa;PWD=111111;DATABASE=hljdatabase"; // 需要修改自己的服务器地址,用户名,密码 <br /> objdbConn.Open(strdsn); <br /> objdbConn.Execute("update 表 set 关联=0"); // 请写入自己的执行语句 <br /> document.write("更新数据成功!<br>"); <br /> objdbConn.Close(); <br /> //--> <br />