connect to an access database using javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mustang123
    New Member
    • Sep 2007
    • 2

    #16
    Hi Dorin,

    Thanks a lot for this post. It helped me in my application.

    One thing I am still searching is that the data is retrieved if SQL is pointing to a table and not a query object which has some functions called.

    Thanks anyways

    regards
    mustang123

    Originally posted by dorinbogdan
    You can connect to database from client-side script, if MDAC is installed on client's computer.
    Just Update strConn with the correct Data Source, and SQL query as desired.
    Code:
    <html>
    	<head>
    		<title>Entitled Document</title>
    		<script language="JavaScript">
    		function getCount(){
    			var cn = new ActiveXObject("ADODB.Connection");
    			var strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = C:\clientDB.mdb;Persist Security Info=False";
    			cn.Open(strConn);
    			var rs = new ActiveXObject("ADODB.Recordset");
    			var SQL = "select count(*) from Customers";
    			rs.Open(SQL, cn);
    			alert(rs(0));
    			rs.Close();
    			cn.Close(); 
    			
    		}
    		</script>
    	</head>
    	<body>
    		<input type="button" value="Get count" onclick="getCount()">
    	</body>
    </html>
    Did it help?

    Comment

    • dorinbogdan
      Recognized Expert Contributor
      • Feb 2007
      • 839

      #17
      See this link.
      Code:
      ...
      rs.Open("yourTableName",cn, 1, 1, 2);
      ...
      Be blessed.

      Comment

      • dubbmac
        New Member
        • Apr 2009
        • 1

        #18
        ACCESSdb JavaScript Library

        I found a JavaScript library that allows you to execute SQL queries in a single command with the option of selecting the output format of the result-set from choices including JSON, XML, and HTML.

        The library is called ACCESSdb and you can get it here: http://www.accessdb.org/
        Last edited by dubbmac; Apr 21 '09, 05:43 PM. Reason: simplify

        Comment

        Working...