admin管理员组

文章数量:1394130

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"

<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>

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"

<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>
Share Improve this question edited Feb 20, 2014 at 10:00 user3094600 asked Feb 20, 2014 at 9:52 user3094600user3094600 291 gold badge2 silver badges7 bronze badges 2
  • FYI: this code only for Internet Explorer – Zam Commented Feb 20, 2014 at 10:03
  • You also miss tag <FORM> – Zam Commented Feb 20, 2014 at 10:04
Add a ment  | 

1 Answer 1

Reset to default 5

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.

If you want to add records to the table you need to .Close that recordset and then re-open it using an SQL mand like SELECT * FROM data (note: no COUNT()). That should allow you to use .AddNew and .Update to insert new records.

本文标签: Connecting to MS Access using JavascriptStack Overflow