从javascript访问ms的数据

时间:2015-04-09 07:55:43

标签: javascript ms-access

我只想问我的代码中有什么问题或遗漏,我无法在我的数据库中插入数据。我也搜索了这个网站,并在那里使用了代码,但它没有插入数据。提前谢谢!

    var adVarWChar = 202;
    var adParamInput = 1;
    var fnamer = document.getElementById('firstn');
    var lnamer = document.getElementById('lastn').value;
    var usernr = document.getElementById('uname').value;
    var passwr = document.getElementById('pword').value;




var con = new ActiveXObject("ADODB.Connection");
var constring = "Microsoft.ACE.OLEDB.12.0;Data Source = Z:\JS\javascriptdb.accdb";
var cmd = new ActiveObject("ADODB.Command");
cmd.ActiveConnection = con;
con.Open();
cmd.CommandText = "Insert into register(firstn,lastn,usern,passw)Values(?,?,?,?)";

cmd.Parameters.Append(cmd.CreateParameter("?",advarWChar,adParamInput,50,fnamer));
cmd.Parameters.Append(cmd.CreateParameter("?",advarWChar,adParamInput,50,lnamer));
cmd.Parameters.Append(cmd.CreateParameter("?",advarWChar,adParamInput,50,usernr));
cmd.Parameters.Append(cmd.CreateParameter("?",advarWChar,adParamInput,50,passwr));

cmd.Execute();
con.Close();

0 个答案:

没有答案