Connecting to MS Access using Javascript - Stack Overflow

I tried the following code for establishing a connection with a database(MS Access)..But am getting an

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744086828a4556330.html

相关推荐

  • Connecting to MS Access using Javascript - Stack Overflow

    I tried the following code for establishing a connection with a database(MS Access)..But am getting an

    9天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信