Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Writing to access database

    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.

    Code:
    ///////////////////////////////////////////
    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");
    
    adoConn.Open(conn_str);
    adoRS.Open("Select * From charges", adoConn, 1, 3);
    
    adoRS.AddNew;
    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;
    adoRS.Update;
    
    adoRS.Close();
    adoConn.Close();
    }
    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?

    Thanks,
    Ben White

    edit:
    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?
    http://www.codingforums.com/showthread.php?t=109627
    Last edited by BenWhite; 08-15-2008 at 08:07 PM.

  • #2
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Aug 2008
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •