使用 Javascript 连接到 MS Access
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21904116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Connecting to MS Access using Javascript
提问by user3094600
I tried the following code for establishing a connection with a database(MS Access)..But am getting an error as "Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype"
我尝试了以下代码来建立与数据库的连接(MS Access)。但我收到错误消息“当前记录集不支持更新。这可能是提供者或所选锁类型的限制”
<html>
<head>
<title>Insertion</title>
<script type="text/javascript" language="JavaScript" >
function AddRecord(form) {
var cn = new ActiveXObject("ADODB.Connection");
var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Users\deepakgopal\Desktop\Testing\Database3.mdb";
cn.Open(strConn);
var rs = new ActiveXObject("ADODB.Recordset");
var SQL = "select count(*) from data";
rs.Open(SQL, cn);
alert(rs(0));
rs.AddNew
rs.Fields("VDI") = Request.Form("vdi");
rs.Fields("Staff") = Request.Form("staff");
rs.Update;
rs.Close();
cn.Close();
}
</script>
</head>
<body style="margin:0 auto;">
VDI: <input type="text" id="tname" name="vdi" />
<br />
Staff : <input type="text" id="tpwd" name="staff" />
<br />
<input type="button" id="btnsbt" name="btnsbt" value="Login" onclick="AddRecord()" /><br />
</body>
</html>
回答by Gord Thompson
The Recordset you are retrieving only contains a single row with a single column containing the count (COUNT(*)
) of all records in the table. That Recordset contains no other information and is not updatable.
您正在检索的 Recordset 仅包含一行和一列,其中包含COUNT(*)
表中所有记录的计数 ( )。该记录集不包含其他信息并且不可更新。
If you want to add records to the table you need to .Close
that recordset and then re-open it using an SQL command like SELECT * FROM data
(note: no COUNT()
). That should allow you to use .AddNew
and .Update
to insert new records.
如果要将记录添加到表中,则需要添加到.Close
该记录集,然后使用 SQL 命令SELECT * FROM data
(如(注意:否COUNT()
))重新打开它。这应该允许您使用.AddNew
和.Update
插入新记录。