[英]Using JavaScript to modify a Microsoft Access database using ADODB
I'm trying to insert values into a Microsoft Access database using JavaScript.我正在尝试使用 JavaScript 将值插入到 Microsoft Access 数据库中。 I'm working with Visual Studio 2010. I have tried many different methods but the code below throws the error: “Localhost not responding.”
我正在使用 Visual Studio 2010。我尝试了许多不同的方法,但下面的代码抛出错误:“本地主机没有响应。” 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.因此,与其走这条路,我建议您使用某种服务器软件,如 ASP.NET 或 PHP 来访问您的数据库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.