简体   繁体   中英

Using JavaScript to modify a Microsoft Access database using ADODB

I'm trying to insert values into a Microsoft Access database using JavaScript. I'm working with Visual Studio 2010. I have tried many different methods but the code below throws the error: “Localhost not responding.” What could be causing this error, and how can I fix it?

function Submit() {
    var fname = document.getElementById("firstName").value;
    var lname = document.getElementById("lastName").value;
    var phnum = document.getElementById("phoneNo").value;
    var uname = document.getElementById("userName").value;
    var pword = document.getElementById("passWord").value;     
    var con = new ActiveXObject("ADODB.Connection");

    con.open = "Provider=Microsoft.Jet.OLEDB.4.0;data source= C:\Users\Adetayo.Odusole\Desktop\Personal\Personal\VB.Net\Personal Website Design\CashRegister.mdb";
    var cmd = new ActiveXObject("ADODB.Command");
    cmd.ActiveConnection = con;
    cmd.CommandText= "Insert into register(Firstname,Lastname,PhoneNum,Username,Password) Values('" & fname & "','" & lname & "','" & phnum & "','" & usernn & "','" & passw & "')";
    cmd.Execute();
    cmd.Close();

}

Instead of fixing your code I had like to give some advice: don't do this!

You are exposing your server file to the web directly. And since your use a local path to access your file, it will access the file on every client machine, not the server. This is prohibited by browsers since they don't allow direct access to files on client machines.

So instead of going this path, I would recommend to use some kind of server software, like ASP.NET or PHP to access your database.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM