以下是一个JavaScript连接Access数据库的例子,问题是,为什么我运行时,点击“写记录测试”,“删除记录测试的链接”没有任何反应?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>js读写Access</title>
</head>
<body>
请按数据库文件实际存放位置进行修改<br>
连接ACCESS数据库<br>
var db="C:/Documents and Settings/Administrator/桌面/DB_sdq.mdb";<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td id="xx1"> </td>
<td id="xx2"> </td>
<td> </td>
<td><a onclick="writedb();" href="#">写记录测试</a> <a onclick="deldb();" href="#">删除记录测试</a></td>
</tr>
</table>
<label id="xx3"></label>
<script language="javascript">
//连接ACCESS数据库
var db="C:/Documents and Settings/Administrator/桌面/DB_sdq.mdb";
function opendb(dbname,sql)
{
var opendb =new ActiveXObject("ADODB.Recordset")
opendb.ActiveConnection = "DBQ="+dbname+";DRIVER={Microsoft Access Driver (*.mdb)};"
opendb.Source = sql
opendb.CursorType = 1
opendb.CursorLocation = 2
opendb.LockType = 3
opendb.Open()
return opendb
}
//读ACCESS数据库
var rs=new Object();
rs=opendb(db,"select * from db_sdq where id="+1);
if (!rs.EOF)
{
document.all.xx1.innerHTML=rs("db_year");
document.all.xx2.innerHTML=rs("db_month");
document.all.xx3.innerHTML=rs("db_year")+"-"+rs("db_month");
}
rs.CLOSE;
//写ACCESS数据库
function writedb()
{
rs=opendb(db,"select * from db_sdq where id="+0);
rs.ADDNEW;
rs("db_year")=2009;
rs("db_month")=5;
rs.UPDATE;
rs.CLOSE
alert("写记录测试成功!");
}
//删除当月重复数据
function deldb()
{
rs=opendb(db,"select * from db_sdq where db_year="+2009+" and db_month="+5+"");
while(!rs.EOF)
{
rs.DELETE;
rs.MOVENEXT;
}
rs.CLOSE
alert("删除记录测试成功!");
}
</script>
</body>
</html>
|