Menu
I have a database with one table and I am trying to write data to it using only javascript. I have the connection string set up but do not know how to use javascript to access the DB and read/write to it. any help would be greatly appreciated. Thanks
<i>
</i>function AddRecord() {
var adoConn = new ActiveXObject("ADODB.Connection");
var adoRS = new ActiveXObject("ADODB.Recordset");
adoConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='/dbName.mdb'");
adoRS.Open("Select * From tblName", adoConn, 1, 3);
adoRS.AddNew;
adoRS.Fields("FieldName").value = "Quentin";
adoRS.Update;
adoRS.Close();
adoConn.Close();
}
<i>
</i>function DeleteRecord() {
var adoConn = new ActiveXObject("ADODB.Connection");
var adoRS = new ActiveXObject("ADODB.Recordset");
adoConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='\dbName.mdb'");
adoRS.Open("Select * From tblName Where FieldName = 'Quentin'", adoConn, 1, 3);
adoRS.Delete;
adoRS.Delete;
adoRS.Close();
adoConn.Close();
}
<i>
</i>function EditRecord() {
var adoConn = new ActiveXObject("ADODB.Connection");
var adoRS = new ActiveXObject("ADODB.Recordset");
adoConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='\dbName.mdb'");
adoRS.Open("Select * From tblName Where FieldName = 'Quentin'", adoConn, 1, 3);
adoRS.Edit;
adoRS.Fields("FieldName").value = "New Name";
adoRS.Update;
adoRS.Close();
adoConn.Close();
}
<html>
<head>
<title>Access db Connection</title>
</head>
</html>
hi ,,
thanks but i cant get all data rows from my db ,.,please help me thanks in advance[/QUOTE]
This code does the trick:
<script type="text/javascript">
var pad = "D:Flipper Documenten data.mdb";
var cn = new ActiveXObject("ADODB.Connection");
var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pad;
cn.Open(strConn);
var rs = new ActiveXObject("ADODB.Recordset");
var SQL = "SELECT * FROM datatable";
rs.Open(SQL, cn);
if(!rs.bof) {
rs.MoveFirst();
if(!rs.eof) {
document.write("<p>" + rs.fields(1).value + ", ");
document.write(rs.fields(2).value + ", ");
document.write(rs.fields(3).value + ".</p>");
}
}
else {
document.write("No data found");
};
rs.Close();
cn.Close();
</script>
It only works with InternetExplorer or in Firefox with the IEtab set to Internet Explorer.[/QUOTE]
0.1.9 — BETA 5.4