Reading/Writing data in MS-Access database using javascript
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
You can't write into a database with javascript, cause javascript works on the client-side not on the server-side, for this you need a server side language, in your case probably one like ASP, JSP, Perl etc.
I know this post is old but I wanted to post this incase anyone else has this same question. Yes you can access a MS Access Database Client-Side with JavaScript here are some examples:
Adding a Record
Code:
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();
}
Removing a Record
Code:
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();
}
Editing a Record
Code:
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();
}
I hope this helps anyone who was trying to do this.
You can indeed connect to a Microsoft Access database from JavaScript.
I had a situation where this functionality was actually useful, so I wrote a JavaScript library to simplify the process. It allows you to execute full SQL queries in a single command directly from JavaScript - with the option to select the desired format of the result-set with formats including JSON, XML, and HTML.
I had a great deal of difficulty finding information or examples of how to connect to do this, so I decided to share my code with the world...
The library is called ACCESSdb and you can get it here!
Hi faulkj,
I accidently found your javascript library "accessdb" on the internet because i was looking for a way to get data out of a MSAccess-database and put it on a simple HTML-page.
Maybe I am overlooking something, but as the result of my query, I get "[object Object] " per element in the returned javascript array.
Here's my HTML/javascript I am trying to get to work:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
document.write('<p>Resultaat van de AccessDB-query:</p>');
var myDB = new ACCESSdb("D:\\Filip\\Documenten\\BNPPFortis\\CCB.mdb", {showErrors:true});
var SQL = "SELECT * FROM Agent";
var SQLresultSet = myDB.query(SQL);
if(myDB.query(SQL)) {
document.write(SQLresultSet[1]);
}
</script>
<p>Einde resultaat van de AccessDB-query</p>
</body>
</html>
Can you help me out ?
Anyway, I need a simple way to create a dynamic HTML-page, not using any server side scripting tool/language. And that's what your script/library is just doing !!!
Java refers to several computer software products and specifications from Sun Microsystems (which has since merged with Oracle Corporation), that together provide a system for developing application software and deploying it in a cross-platform environment. Java is used in a wide variety of computing platforms from embedded devices and mobile phones on the low end, to enterprise servers and supercomputers on the high end.
.
This does not work on my PC. Are there some settings I need to make in IE8 that will allow the object to be created and work? I keep getting an undefined error!
hi im a beginner in javascript
i have used the script given above in this thread. but im not able to connect to database. pls help me.. i m using acess 2007. pls find the below script
<HTML>
<head>
<script>
function AddRecord()
{
var adoConn = new ActiveXObject("ADODB.Connection");
var adoRS = new ActiveXObject("ADODB.Recordset");
adoConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='C:\Documents and Settings\user\Desktop\v.mdb'");
adoRS.Open("Select * From u", adoConn, 1, 2);
Bookmarks