用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;
}
相关推荐
标题中的“由MDB数据库自动生成HTML表格文件.rar_表格 数据库”揭示了这个压缩包内容的核心,即一个涉及MDB数据库(Microsoft Access的数据库文件格式)与HTML表格相互转换的示例。MDB数据库常用于存储结构化的数据...
在本课程中,使用的示例数据库rsgl.mdb包含了一个“职工工资”表,包含多个字段如部门、编号、姓名和各种薪酬项,用于演示如何在ASP中操作这些数据。 5. **课堂教学**深入探讨了ADO的核心概念: - **ADO对象模型**...
Flash-ASP-数据库交互技术详解 在本文中,我们将探讨 Flash 与数据库的交互技术,涵盖 Flash 读取数据库中的数据和 Flash 写数据到数据库两方面的内容。 Flash 读取数据库中的数据 要读取数据库中的数据,需要...
标题中的“13000条成语典故MDB数据库”指的是一个包含13000个成语及其典故的数据库,这种数据库通常用于存储大量结构化的成语数据,方便进行查询、分析或开发相关应用。MDB是Microsoft Access的数据库文件格式,这是...
在ASP中,我们可以使用ADO(ActiveX Data Objects)来连接和操作MDB数据库,执行查询、插入、更新和删除等操作。 在这个"asp+Ajax+mdb数据库,无刷新检测用户名是否占用"的例子中,我们看到的是一个Web应用程序功能...
在JavaScript中,与Access数据库进行交互通常涉及到使用ActiveX对象,因为JavaScript本身并不直接支持数据库操作。Access数据库是一种关系型数据库管理系统,适用于小型项目或本地数据存储。在Web应用程序中,如果你...
"asp"目录可能包含了示例的ASP代码,"css"可能用于美化展示,"images"可能包含帮助理解的图片,而"js"目录则可能包含了一些JavaScript代码,用于辅助处理前端的字符编码问题。 总之,解决UTF-8编码的Access数据库在...
它结合了前端JavaScript的动态性与后台ASP的处理能力,同时利用数据库存储和管理菜单数据,确保了菜单系统的稳定性和可维护性。对于需要构建复杂菜单结构的ASP开发者来说,这是一个非常实用的解决方案。
在标题"JS操作ACCESS数据库"中,所提及的是利用JavaScript来操作Microsoft Access数据库的技术。Access是一款关系型数据库管理系统,它提供了ODBC(开放数据库连接)接口,使得其他编程语言,包括JavaScript,可以...
- 如果可能,建议使用服务器端脚本来处理数据库操作,这样可以更好地控制安全性。 - 在生产环境中使用此方法时,请确保进行了充分的安全测试和加固措施。 #### 五、总结 通过以上介绍,我们可以了解到如何使用 ...
然而,JavaScript也可以用来操作数据库,尽管这并不常见,特别是在处理像Access这样的桌面数据库时。在标题“js操作access数据库”中,我们讨论的是如何使用JavaScript与Microsoft Access数据库进行交互。 Access...
今天我们将聚焦于一个特定的Node.js模块——"node-mdb-sql",它为开发者提供了一种在JavaScript中操作mdb(Access数据库)文件的便捷方式。 "node-mdb-sql"是专门为处理Microsoft Access数据库而设计的Node.js库。...
"自用Java代码和Memento数据库" 表示这个项目不仅包含了JavaScript脚本,还涉及了Java代码,这可能用于与Memento数据库进行交互或者处理数据。自用意味着这些代码可能最初是为个人项目设计的,但它们可能对其他...
在ASP中,我们可以使用ADO(ActiveX Data Objects)库来处理数据库操作。以下是一个基本的ASP连接示例: ```asp Dim conn Set conn = Server.CreateObject("ADODB.Connection") conn.Open "Provider=Microsoft.Jet...
3. **数据库**:项目中提到了一个名为"address.mdb"的文件,这很可能是Access数据库,用于存储省市县的层次关系数据。数据库中的结构可能包括省份、城市和县(区)的ID、名称等字段,以支持联动效果。 4. **...
标题中的“Javascript连接Access数据库的代码”指的是使用JavaScript编程语言来与Microsoft Access数据库进行交互的实现方式。在描述中提到,作者花费了一定精力在网络上寻找并整理了这段代码,但发现由于权限限制,...
在本项目“邮编查询系统v1.0”中,我们将探讨如何利用JavaScript与Microsoft Access数据库进行通信,实现一个简单的邮编查询功能。这个系统可能适用于那些需要快速查找特定地区邮编的场景,如物流配送、地址验证等。...
2. **数据库文件**:通常是".mdb"扩展名的Access数据库文件,例如"CustomerDatabase.mdb",包含了客户信息表和其他可能的相关业务数据。 3. **CSS文件**:用于定义页面样式,如"styles.css",使网页具有统一的外观和...
首先,我们需要了解ASP与MDB数据库的交互。ASP是微软提供的一种服务器端脚本技术,它允许开发者创建动态网页。而MDB是Access数据库的文件格式,存储结构化数据。在ASP中,我们可以使用ADO(ActiveX Data Objects)来...