Solved

Javascript + HTML + Access database. Is it possible to coexist without a web server?

Posted on 2010-08-31
10
314 Views
Last Modified: 2012-05-10
Helllo experts,

I would like to know if it is possible to retrieve/update a MS Access database by using Javascript, HTML only without having to have a web server. I have a snippet of code and would like to know if it is correct. thanks!
<html>     
<head>         
<title>Populate Dropdown Using JScript</title>         
<script language="text/Jscript">         

function loadData()       
{       
      var appPath;
      var cn;
      var rs;
      var sql;
      var conn;

      try {
            rs = new ActiveXObject("ADODB.Recordset");
      }
      catch (e) {
            alert("ADODB namespace not found.");
            exit(0);
      }

      appPath = "c:\QTPDb.accdb"

      conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + appPath + ";Persist Security Info=False"; 

      var sql = "select ColA from TableA";             
      rs.Open(sql, cn);       

      rs.open(sql, conn,0, 1, 1);
      
      rs.movefirst();
      while (rs.eof != true) {
            var optn = document.createElement("OPTION");
            optn.text = rs("ColA");
            optn.value = value;
            document.mylist.options.add(optn);
      }      


      rs.Close();                   
}         



</script>     


</head>

<body onload=loadData()>        

<SELECT name="mylist">
</SELECT>

</body>  
</html>

Open in new window

0
Comment
Question by:DoofuS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 16

Expert Comment

by:carsRST
ID: 33569560
I'm not in a position to test your code, but looks reasonable.  The only things I see you'll probably have to change is the connection string for Access 2007 (see below) and add a connection activeX (see below).

Access 2007 Connection string:
Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Persist Security Info=False;

Connection Code:
var conn = new ActiveXObject("ADODB.Connection")
0
 

Author Comment

by:DoofuS
ID: 33569853
Thanks. I will make that change and run it...my earlier run with the original code resulted in an error.
0
 

Author Comment

by:DoofuS
ID: 33570309
I have modified a bit per your suggestion, I still can't get this working. I have this named as Test.html and it is stored in the same directory as the access db. Any ideas?
<html>     
<head>         
<title>Populate Dropdown Using JScript</title>         
<script type="text/javascript">        

function loadData()       
{       
      var appPath;
      var conn;
      var conn_str;
      var rs;
      var sql;  

      conn_str= "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\QTPDb.accdb;Persist Security Info=False;"; 	
      conn = new ActiveXObject("ADODB.Connection");
      alert("Before Connexn Setup");  
      conn.open(conn_str)
      alert("After Connexn Setup"); 
      rs = new ActiveXObject("ADODB.Recordset");
      
      sql = "select CauseOfLoss1 from IMContEquip1";             
      rs.Open(sql, conn );        
      
      rs.movefirst(); 
      while (rs.eof != true) {
            var optn = document.createElement("OPTION");
            optn.text = rs(0);
            optn.value = value;
            document.mylist.options.add(optn);
      }      

      rs.Close();                   
}         



</script>     
</head>

<body>  
<form name="frm" method="post">
     <table>
	<TR>
           <TD><INPUT name="btnSubmit" TYPE="Submit" VALUE="Submit"  onclick = "return loadData()"></TD> 
        </TR>
                
     </table>
</form>
	

<SELECT name="mylist">
</SELECT>

</body>  
</html>

Open in new window

0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 16

Accepted Solution

by:
carsRST earned 500 total points
ID: 33570319
Got a chance to test it out.  Here's a basic script i know works.  All you need to do is change up to your data and output.
<html>

<head>

<title>Populate Dropdown Using JScript</title>

<script>

function loadData()

{
      var cn;

      var rs;


      var sql;

      var conn;

       var sql;

	rs = new ActiveXObject("ADODB.Recordset");



	conn = new ActiveXObject("ADODB.Connection");


	val = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "C:/finance/../myDB.mdb" + ";Persist Security Info=False";

	conn.open (val);

	rs.open ("select ID from tbl_log", conn);


	do {

		    alert(rs("ID"));

		    rs.movenext;

	} while(!rs.eof);

}



</script>

</head>

 
<body>


<INPUT TYPE="BUTTON" OnClick="loadData();" VALUE="Go!!!">

</body>

</html>

Open in new window

0
 
LVL 16

Expert Comment

by:carsRST
ID: 33570334
Just to test...

Change this line to your SQL:
rs.open ("select ID from tbl_log", conn);

And this line to new Access connection string and database path::
val = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "C:/finance/../myDB.mdb" + ";Persist Security Info=False";
0
 

Author Comment

by:DoofuS
ID: 33570407
I have a Ms access 2007 database. Would that affect anything in the connection string?
0
 
LVL 16

Expert Comment

by:carsRST
ID: 33570437
Yes, sorry.  I was only able to test in 2003.  Just change the connection string (like you did before).  It's different for 2007.

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\myFolder\myAccess2007file.accdb;Persist Security Info=False;
0
 
LVL 16

Expert Comment

by:carsRST
ID: 33570458
Here's what it should look like:

conn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + appPath  + ";Persist Security Info=False;";
0
 

Author Comment

by:DoofuS
ID: 33570474
Cool...I have changed the connection string to this:

conn_str= "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\QTPDb.accdb;Persist Security Info=False;";       
   
Thanks a million :)!!!
0
 

Author Closing Comment

by:DoofuS
ID: 33570480
Awesome solution!
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Jquery form 9 43
CSS for <center> 14 35
DataTable column sorting incorrectly 2 22
html5 1 19
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question