Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to write to access db using javascript? 1

Status
Not open for further replies.

jfdabiri

MIS
Feb 27, 2007
282
US
hi, i have this code:
Code:
Const adOpenStatic = 3
Const adLockOptimistic = 3 
 
db_path = "orders.mdb"   
db_file = db_path 
 
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet  = CreateObject("ADODB.Recordset")
objConnection.Open _
   "Provider = Microsoft.Jet.OLEDB.4.0; " & _
   "Data Source = " & db_path

    commandstring = "INSERT INTO orders " & _   
                    "(model, amt, dte) " & _ 
                    "VALUES (" & _                            
                    chr(39)& model     & chr(39)& ", " & _ 
                    chr(39)& amt       & chr(39)& ", " & _ 
                    chr(39)& date()    & chr(39) & ");"    
 
           objConnection.Execute commandstring 

msgbox "All records were processed successfully" 
objrecordset.close 
objConnection.close
i'm not really familiar with javascript. how would i translate this cod into javascript, please?
thanks.
 
[1] If amt is numeric, you don't need to quote it (chr(39)). (If you need to, restore it in the below.)
[2] Main tricky thing is the datetime data type. I separate out the part for elaboration. I use here date literal format as a possible solution and thereby you don't need additonal quotes (chr(39)).
[3] All lines I leave out below are irrelevant.
[4] I set up sample model, amt (and dte) for completeness.
[tt]
[maroon]var model,amt,dt,dte;
model="model-abc";
amt=12345;
dt=new Date();
dte="#"+(dt.getMonth()+1)+"/"+dt.getDate()+"/"+dt.getFullYear()+"#";[/maroon]

var db_path = "orders.mdb";
var db_file = db_path;
var objConnection = new ActiveXObject("ADODB.Connection");
objConnection.Open ("Provider = Microsoft.Jet.OLEDB.4.0; " + "Data Source = " + db_path);
var commandstring = "INSERT INTO orders " + "(model, amt, dte) " + "VALUES (" + "'" + model + "'" + ", " + amt + ", " + dte + ");";
objConnection.Execute (commandstring);
alert("All records were processed successfully");
objConnection.close();
[/tt]
 
thanks so much tsuji.
it worked great. just great. you deserve a star.
cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top