View Full Version : Writing to access database

08-15-2008, 05:55 PM
Hi, I am trying to write to a DB using javascript. I do realize this is very open to sql injection attacks but this is a completely internal program which is only going to be used by a couple people. I am confused as to how to add to a recordset. I found this on a forum somewhere and edited it to my liking but am not sure exactly how to do the fields correctly.

var strDbPath = "U:\\TraciAccess\\CellDB.mdb";
var conn_str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strDbPath;

function AddRecord(number,name,date,provider,accntCharges,monthlyAccess,usageCharges,equipCharges,vzwCharges, taxesFees,total) {
var adoConn = new ActiveXObject("ADODB.Connection");
var adoRS = new ActiveXObject("ADODB.Recordset");

adoRS.Open("Select * From charges", adoConn, 1, 3);

adoRS.Fields("number").value = "number";
adoRS.Fields("name").value = "name";
adoRS.Fields("date").value = "May 2, 2007";
adoRS.Fields("provider").value = "provider";
adoRS.Fields("accntCharges").value = "accntCharges";
adoRS.Fields("monthlyAccess").value = "monthlyAccess";
adoRS.Fields("usageCharges").value = "usageCharges";
adoRS.Fields("equipCharges").value = "equipCharges";
adoRS.Fields("vzwCharges").value = "vzwCharges";
adoRS.Fields("taxesFees").value = "taxesFees";
adoRS.Fields("total").value = 5;
adoRS.Fields("historyID").value = 0;


The quotes around the variable names just submits it as a string and it wont work without them. How do I make the field equal to the variable?

Ben White

I found a similar post here and he says a little about the solution but doesn't specify enough for me to understand. Anyone have any ideas?

08-15-2008, 09:12 PM
If anyone knows another way to send an insert statement to an access database from javascript I will do that too... I just need to be able to get those variables from my javascript that is already programmed.

08-15-2008, 09:39 PM
Ok, dumb mistake. The data I was using was messed up. I would like to find a more efficient way to do it or find a way to make it asynchronous because it goes slowly. It isn't even going to be loaded on a webserver, someone where I work is just going to click on the html file with the javascript in it to run it.