<script language=JavaScript> //getCountFromDB(); var db = new DataBase("test.html","zhu.mdb"); var rs = db.openRs("SELECT female FROM [zhufei]") while (!rs.eof) { var cnt = rs.Fields("female"); document.write(cnt+","); //将取得结果加1后更新数据库。 //updateCnt = cnt * 1 + 1; rs.moveNext; } rs.close(); rs = null; db.close(); </script>var con; var Class = { create: function() { return function() { this.initialize.apply(this, arguments); } } } var DataBase = new Class.create(); DataBase.prototype = { initialize: function(filename,datafile) { var filePath = location.href.substring(0, location.href.indexOf(filename)); filePath=decodeURI(filePath); var path = filePath + datafile; //去掉字符串中最前面的"files://"这8个字符。 path = path.substring(8); //建立连接,并生成相关字符串 www.knowsky.com。 con = new ActiveXObject("ADODB.Connection"); con.Provider = "Microsoft.Jet.OLEDB.4.0"; con.ConnectionString = "Data Source=" + path; con.open(); }, close:function(){//关闭 con.close(); con = null; }, execute:function(sql){//执行sql不返回 con.execute(sql); }, openRs:function(sql){//执行sql返回rs var rs = new ActiveXObject("ADODB.Recordset"); rs.open(sql, con); return rs; } }
使用方法:
如在test.html文件中使用