JS操作 Access 数据库
- <SCRIPT LANGUAGE="JavaScript">
- <!--
- var filePath = location.href.substring(0, location.href.indexOf("实例197.连接Access数据库.html"));
- var path = filePath + "197.mdb";
- path = path.substring(8);
- var objdbConn = new ActiveXObject("ADODB.Connection");
- var strdsn = "driver={Microsoft Access Driver (*.mdb)};dbq=" + path;
- objdbConn.Open(strdsn);
- document.write("连接ACCESS数据库成功!<br>");
- objdbConn.Close();
- </SCRIPT>
连接SQL Server数据库
- <SCRIPT LANGUAGE="JavaScript">
- <!--
- var objdbConn = new ActiveXObject("ADODB.Connection");
- var strdsn = "Driver={SQL Server};SERVER=(local);UID=sa;PWD=111111;DATABASE=hljdatabase";
- objdbConn.Open(strdsn);
- document.write("数据库连接成功<br>");
- objdbConn.Close();
- </SCRIPT>
查询数据库实例
- <SCRIPT LANGUAGE="JavaScript">
- <!--
- var objdbConn = new ActiveXObject("ADODB.Connection");
- var strdsn = "Driver={SQL Server};SERVER=(local);UID=sa;PWD=111111;DATABASE=hljdatabase";
- objdbConn.Open(strdsn);
- var objrs = objdbConn.Execute("SELECT * FROM 表 where 关联=0");
- var fdCount = objrs.Fields.Count - 1;
- if (!objrs.EOF){
- document.write("<table border=1><tr>");
- for (var i=0; i <= fdCount; i++)
- document.write("<td><b>" + objrs.Fields(i).Name + "</b></td>");
- document.write("</tr>");
-
- while (!objrs.EOF){
- document.write("<tr>");
- for (i=0; i <= fdCount; i++)
- document.write("<td valign=‘top‘>" + objrs.Fields(i).Value + "</td>");
- document.write("</tr>");
- objrs.moveNext();
- }
- document.write("</table>");
- }
- else
- document.write("数据库内没有记录!<br>");
- objrs.Close();
- objdbConn.Close();
- </SCRIPT>
操作数据库实例
- <SCRIPT LANGUAGE="JavaScript">
- <!--
- var objdbConn = new ActiveXObject("ADODB.Connection");
- var strdsn = "Driver={SQL Server};SERVER=(local);UID=sa;PWD=111111;DATABASE=hljdatabase";
- objdbConn.Open(strdsn);
- objdbConn.Execute("update 表 set 关联=0");
- document.write("更新数据成功!<br>");
- objdbConn.Close();
- </SCRIPT>
作用JavaScript访问和操作数据库,布布扣,bubuko.com
作用JavaScript访问和操作数据库
原文:http://www.cnblogs.com/ranzige/p/3884583.html