www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 16

Thread: Reading/Writing data in MS-Access database using javascript

  1. #1
    Join Date
    Jan 2003
    Posts
    1

    Question 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

  2. #2
    Join Date
    Dec 2002
    Location
    Switzerland
    Posts
    428
    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.


    Swon

  3. #3
    Join Date
    Jun 2004
    Location
    United States (Currently in Iraq)
    Posts
    60
    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.
    Last edited by Quentin; 06-30-2004 at 12:34 PM.
    Q

  4. #4
    Join Date
    Apr 2009
    Posts
    1

    Arrow ACCESSdb JavaScript Library

    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!



  5. #5
    Join Date
    Feb 2012
    Posts
    3
    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>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

    <title>test javascript</title>

    <script type="text/javascript" src="accessdb.js"></script>

    </head>

    <body>

    <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 !!!

  6. #6
    Join Date
    Mar 2012
    Posts
    2

    same probem

    I'm having the same issue and desperately need to be able to read an access database locally from a web page. HELP!!

  7. #7
    Join Date
    Feb 2012
    Posts
    3
    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.

  8. #8
    Join Date
    Mar 2012
    Posts
    5

    java

    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.
    .

  9. #9
    Join Date
    Mar 2012
    Posts
    2
    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!

  10. #10
    Join Date
    Feb 2012
    Posts
    3
    No, I did not make any changed to my IE-settings. Of course you have to allow javascript to run in your browser.

  11. #11
    Join Date
    Nov 2012
    Posts
    1

    pls help me

    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);

    document.write("c");
    adoRS.Close();
    adoConn.Close();
    }

    </script>
    </head>
    <body>
    <input type="button" value="sub" onclick="AddRecord()">
    </body>
    </html>

    thanks in advance

  12. #12
    Join Date
    Apr 2013
    Posts
    1

    Thumbs up

    Hi Flippervan65,
    thank you, you're code really did the trick.
    I've been trying this for really long...

    I've done little modification to connect access'2007 database and that also worked.


    <html>
    <head>
    <title>Access db Connection</title>


    <script type="text/javascript">

    //var pad = "C:\\Users\\Admin\\Documents\\TestDB.mdb";
    var pad = "C:\\Users\\Admin\\Documents\\TestDB.accdb";

    //var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pad;
    var strConn = "Provider=microsoft.ace.oledb.12.0;Data Source=" + pad;

    var cn = new ActiveXObject("ADODB.Connection");

    cn.Open(strConn);
    var rs = new ActiveXObject("ADODB.Recordset");
    var SQL = "SELECT * FROM customer_mas WHERE ID='512225'";
    rs.Open(SQL, cn);
    if(!rs.bof) {
    rs.MoveFirst();
    if(!rs.eof) {
    document.write("<p><br>" + rs.fields(1).value + ", ");
    document.write("<br>" + rs.fields(2).value + ", ");
    document.write("<br>" + rs.fields(3).value + ".</p>");
    }
    }
    else {
    document.write("No data found");
    };
    rs.Close();
    cn.Close();

    </script>

    </head>

    </html>

  13. #13
    Join Date
    Jun 2013
    Posts
    1
    Curious, using accessdb.js, has anyone connected to an Access 2007/2010, accdb, using encryption and a mdw file? I can use the 2007/2010 DB without encryption, but I get the error below when accessing the DB with the encryption turned on and a mdw file.

    Error!Error
    Cannot start your application. The workgroup information file is missing or opened exclusively by another user.

    I know I am missing something, but not sure what. I have created the MDW file and joined it to the DB with no success.

    Appreciate it, anyone has had success using a Access 2007/2010 with the encryption turned on.

    Thanks,

  14. #14
    Join Date
    Sep 2013
    Posts
    1
    hi ,,

    thanks but i cant get all data rows from my db ,.,please help me thanks in advance

  15. #15
    Join Date
    May 2014
    Posts
    2
    Hello,
    This is my code for insert data to acess database I can't get it to work Need some help. Thanks.

    function insert(){
    var today= new Date().toLocaleDateString();
    var pad = "C:\\Users\\axmar18\\Documents\\feedback.accdb";
    var cn = new ActiveXObject("ADODB.Connection");
    var rs = new ActiveXObject("ADODB.Recordset");

    var strConn = "Provider=microsoft.ace.oledb.12.0;Data Source=" + pad;
    cn.Open(strConn);

    rs.Open("SELECT * FROM feedback", cn);
    rs.AddNew;
    rs.Fields(field(1).value = "100";
    rs.Update;

    rs.Close();
    cn.Close();
    }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles