用js操作mdb数据库的一些操作,包括数据的读取和存储;
html页面信息
mdb数据库表一
mdb数据库表二
具体代码如下:
//获得fileName的路径;
function serverMapPath(fileName) {
var syspath = location.href; //file:///c:/Documents%20and%20Settings/Administrator/桌面/新建文件夹/handle-mdb.html
alert(syspath)
syspath = syspath.toLowerCase();
myPosition = syspath.lastIndexOf("/");
syspath = syspath.substring(0, parseInt(myPosition) + 1);
syspath = syspath.replace("file:///", "");
syspath = syspath.replace(new RegExp("%20", "gm"), " ");
syspath = syspath + fileName; //c:/documents and settings/administrator/桌面/新建文件夹/Database.mdb;
alert(syspath)
return syspath.toString();
}
//获取mdb数据库中的数据到html-方法1-多字段名称;
function loadData(LibleName) {
var conn = new ActiveXObject("ADODB.Connection");
var connStr = "DBQ=" + serverMapPath("Database.mdb") + ";DRIVER={Microsoft Access Driver (*.mdb)};"
//打开数据库;
conn.Open(connStr);
var rs = new ActiveXObject("ADODB.Recordset");
var sql = "select * from " + LibleName;
//打开记录集;
rs.open(sql, conn);
while (!rs.EOF) {
var feildName = "";
var valueCell = "";
var inputs = document.getElementsByTagName("input");
var textAreas = document.getElementsByTagName("textarea");
//rs.fields.count为字段名称的总数;
for(var z=0;rs.fields.count>z;z++){
//filedName为字段名称;
filedName = rs(z).Name;
//mdb中各字段内存储的值;
valueCell = (rs.Fields(filedName).Value);
if (valueCell == null){
valueCell = "";
}
for (var i = 0; i < inputs.length; i++) {
var inputCell = inputs[i];
if(filedName==inputCell.id){
inputCell.value=valueCell;
}
}
for (var j = 0; j < textAreas.length; j++){
var textAreaCell = textAreas[j];
if (filedName == textAreas.id){
textAreaCell.value = valueCell;
}
}
}
rs.moveNext();
}
rs.close;
rs = null;
}
//获取mdb数据库中的数据到html-方法2-两个字段名称-一个ID,一个name;
function Show(tableName) {
var str =tableName;
var conn = new ActiveXObject("ADODB.Connection");
var connStr = "DBQ=" + serverMapPath("Database.mdb") + ";DRIVER={Microsoft Access Driver (*.mdb)};"
conn.Open(connStr);
var rs = new ActiveXObject("ADODB.Recordset");
var sql = "select * from "+str+" order by id";
rs.open(sql, conn);
theInput = null;
while (!rs.EOF) {
var htmlID = "";
var value = "";
//mdb中的ID是正整数,html中的ID由四位数字组成,位数不够的用0不足;
//如mdb中的‘1’,html中是‘0001’;
htmlID = rs.Fields("id").value;
if(htmlID.length==1){
htmlID = '000'+htmlID;
}else if(htmlID.length==2){
htmlID='00'+htmlID;
}else if(s.length==3){
htmlID='0'+htmlID;
}
try
{
theInput = document.getElementById(htmlID);
if (theInput !== null){
value = (rs.Fields("name").Value);
if (theInput.type == "text"){
theInput.value = value;
}
if (theInput.type == "textarea") {
theInput.value = value;
}
if (theInput.type == "radio"){
if (value == "√"){theInput.checked = true}
if (value == "□"){theInput.checked = false}
}
if (theInput.type == "checkbox"){
if (value == "√"){theInput.checked = true}
if (value == "□"){theInput.checked = false}
}
if (theInput.name == "select") {
for(j = 0; j< theInput.length ; j++){
if (theInput.options[j].value == value) {
theInput.options[j].selected = true;
}
}
}
//name是值为‘uu’的处理;
if(theInput.className == "uu"){
theInput.innerHTML = value;
}
}
}
catch(E)
{
}
rs.moveNext();
}
conn.close();
conn = null;
}
//把html中填写的内容更新到数据库;
function update(str) {
var conn = new ActiveXObject("ADODB.Connection");
var connStr = "DBQ=" + serverMapPath("Database.mdb") + ";DRIVER={Microsoft Access Driver (*.mdb)};"
conn.Open(connStr);
InputList = document.getElementsByTagName("input");
TheInput = null;
for(i = 0; i < InputList.length; i++) {
TheInput = InputList[i];
var TheInputId = TheInput.id;
TheInputId = parseInt(TheInputId,10);
if(!isNaN(TheInputId)){
if (TheInput !== null){
//radio单选框的处理
if (TheInput.type == "radio"){
var sql = "delete from "+ str +" where id = '"+ TheInputId+"'";
conn.execute(sql);
if (TheInput.checked == true){
var sql = "insert into "+ str +" values("+ TheInputId +",'" + "√" + "')";
conn.execute(sql);
}
if (TheInput.checked == false){
var sql = "insert into "+ str +" values("+ TheInputId +",'" + "□" + "')";
conn.execute(sql);
}
}
//checkbox复选框的处理;
if (TheInput.type == "checkbox"){
var sql = "delete from "+ str +" where id = '"+ TheInputId+"'";
conn.execute(sql);
if (TheInput.checked == true){
var sql = "insert into "+ str +" values("+ TheInputId +",'" + "√" + "')";
conn.execute(sql);
}
if (TheInput.checked == false){
var sql = "insert into "+ str +" values("+ TheInputId +",'" + "□" + "')";
conn.execute(sql);
}
}
//一般文本输入框处理
if (TheInput.type == "text") {
if (TheInput.value !== null){
var sql = "delete from "+ str +" where id = '"+ TheInputId+"'";
conn.execute(sql);
var sql = "insert into " + str + " values(" + TheInputId + ",'" + TheInput.value + "')";
conn.execute(sql);
}
}
//隐藏域的处理
if (TheInput.type == "hidden") {
if (TheInput.value !== null){
var sql = "delete from "+ str +" where id = '"+ TheInputId+"'";
conn.execute(sql);
sql = "insert into " + str + " values(" + TheInputId + ",'" + TheInput.value + "')";
conn.execute(sql);
}
}
}
}
}
//textarea多行文本框;
InputList = document.getElementsByTagName("textarea");
TheInput = null;
for(i = 0; i < InputList.length; i++) {
TheInput = InputList[i];
var TheInputId = TheInput.id;
TheInputId = parseInt(TheInputId,10);
if(!isNaN(TheInputId)){
if (TheInput !== null){
if (TheInput.text !== null){
var sql = "delete from "+ str +" where id = '"+ TheInputId+"'";
conn.execute(sql);
var sql = "insert into "+ str +" values("+ TheInputId +",'" + TheInput.value + "')";
conn.execute(sql);
}
}
}
}
//select下拉框的处理
InputList = document.getElementsByTagName("select");
TheInput = null;
for(i = 0; i < InputList.length; i++) {
TheInput = InputList[i];
var TheInputId = TheInput.id;
TheInputId = parseInt(TheInputId,10);
if(!isNaN(TheInputId)){
if (TheInput !== null){
if (TheInput.name == "select") {
var sql = "delete from "+ str +" where id = '"+ TheInputId+"'";
conn.execute(sql);
for(j = 0; j< TheInput.length; j++){
if (TheInput.options[j].selected) {
var sql = "insert into "+ str +" values("+ TheInputId +",'" + TheInput.options[j].value + "')";
conn.execute(sql);
}
}
}
}
}
}
conn.close();
conn = null;
}
相关推荐
用静态网页的javascript对acess的数据库进行访问,用数据库的值进行显示!
(源代码),JAVASCRIPT修改,新增,删除ACCESS数据库(操作).不需要架设WEB服务器,离线本地操作ACCESS数据库。支持PHP,ASP,.NET,JAVA.
firste_data文件夹中#firste_city.mdb为省、市、县数据库,#firste_city_1.mdb为空数据库,可以通过后台管理数据库中的内容。 后台管理地址:admin/admin_index.asp 用户名和密码都是firste ----------------------...
右键—>所有任务--->还原数据库--->从设备--->指到本目录下的“database/gq.fyasp.com.sql还原。 在安全性-->登陆-->新建用户(一定不要用SA默认账号,同时为SA建一个强有力的20位以上数字字母符号的混合密码) --->...
刚看到一个朋友写的用javascript连接excel数据库的程序,想把它改成access数据库的,就找到了这两篇文章 ------------------------------------------ 这几天费了挺大...
自用Java代码和Memento数据库
db=\"data/data.mdb\" \'数据库存放目录 on error resume next set conn=server.createobject(\"adodb.connection\") conn.open \"driver={microsoft access driver (*.mdb)};dbq=\"&server.mappath(db) if err ...
静态页面读取ACCESS数据库.htm 代码如下: [removed] //用 JavaScript 写服务器端连接数据库的代码示例 var conn = new ActiveXObject(“ADODB.Connection”); conn.Open(“DBQ=E:\\a.mdb;DRIVER={...
能过javascript 访问ACCESS数据库, var myDB = new ACCESSdb("d:/ACCESSdb/AdmnCodes.mdb", { showErrors: true });
数据库修改:Data.asp文件修改,无须后缀名,首次使用可在[Setup.asp]中修改 mdb数据库:修改Data文件任意名 [.mdb]后缀(必须小写)和创建全新mdb文件即可,不能含特殊字符 特点:文件小,见面整洁,设置简单,管理...
tree.mdb -- 动态加载树示例,数据库 alai_imagelist.js -- 图片列表控件程序 Alai_win.js -- 浮动窗口控件程序 Alai_win_xp.js -- 浮动窗口控件程序XP风格版 bihua.js -- 中文字符集,笔画顺序 pingying.js -- ...
1 修改数据库文件的文件名 bizszze.MDB 2 修改连接数据库文件 D_lj.asp 中数据库文件的路径 3 修改RenZheng.asp文件的文件名 4 上传到支持ASP与Access的服务器上 5 点击网页尾部的进入后台连接输入密码111111可进入...
JS操作 Access 数据库 代码如下: [removed] <!– var filePath = location.href....var path = filePath + “197.mdb”; path = path.substring(8); var objdbConn = new ActiveXObject(“ADODB.Co
'网站数据:/Database/NwebCn_Site.mdb (常规内容数据库) ' /Database/Bak_NwebCn_Site.mdb (备份内容数据库) ' /Database/NwebCn_Stat.mdb (常规流量数据库) ' /Database/Bak_NwebCn_Stat.mdb (备份流量数据库) ...
H5MDB 是一个允许您更轻松地实现移动设备 CRUD 的库。 要查看它的工作情况,只需克隆 repo 并使用 Chrome 或 Safari 打开 index.html(或使用 Cordova 编译它并在您的手机中尝试它)。 用法 类 DAO 为您创建所有 sql...
JavaScript操作数据库JS操作Access数据库,跟其他语言操作差不多,总结了一下习惯代码,仅供参考学习。 现在在F盘有文件abc.mdf,表名为Student,一共2个字段,Id数字类型主键,stuName文本类型,现对该表进行增删改...
<br>App_Data/minbel.mdb 数据库文件 <br>使用方法: <br>显示某类新闻的列表 就是说,你要知道该类别ID,在管理里面的[定义类别]列表里而已查到 <a href=../Files/ShowFileList.aspx?TypeID=1>文章1...
里面有详细的说明书,源码。未发布,可以看到所有的.aspx,.cs文件等运用有母版页技术,Javascript等有.bat,.mdb数据库文件,可以在本地运行 数据库为Sqlserver
因为一些原因,算是自学了一下JAVABean的东西,B/S访问MDB数据库,通过表单传递消息,文字页面编码UTF-8存在的种种问题,JSP和JavaScript的区别等等,可以算是很全面的一个模板吧。
4、默认数据库为db#url.mdb(可用记事本打开connDB.asp修改数据库路径或改名等设置,如不了解不要改动) ---------------------------------------------------------------- 【版本更新说明】 ver3.1.2 ·增加是否...