0

Can anyone suggest me how to fetch data from access database using HTML and Javascript in IE8,i have done it in IE9 but while using IE8 same code is not working. heres the code working in IE9: i am getting error msg while running the code in IE8 and not being able to inputbox data in IE8

<html>
   <body>
   <head>  
      <table>
         <tr align="center">
            <td><input type="text" font="tahoma" name="enter" class="enter" id="tblName" value="Enter the table name" onblur="if(this.value == ''){ this.value = 'Enter the table name'; this.style.color = '#AAA';}" onfocus="if(this.value == 'Enter the table name'){ this.value = ''; this.style.color = '#000';}" style="color:#BBB;"/></td>
         </tr>
         <tr align="center">
            <td><input type="text" name="enter" class="enter" id="keywrd" value="Enter the keyword" onblur="if(this.value == ''){ this.value = 'Enter the keyword'; this.style.color = '#BBB';}" onfocus="if(this.value == 'Enter the keyword'){ this.value = ''; this.style.color = '#000';}" style="color:#BBB;"/></td>
         </tr>
         <tr align="center">
            <td><input type="button" value="Search" OnClick="getValueFromTextbox()"/></td>
         </tr>
      </table>
      <script type="text/javascript">
      var adOpenDynamic = 2;
      var adLockOptimistic = 3;
  function getValueFromTextbox()
  {
     tableName = document.getElementById('tblName').value;
     searchStr = document.getElementById('keywrd').value;
     document.write(searchStr );
     showReports();
  }    
  var strDbPath = "f:\\db1.mdb";
     var conn_str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strDbPath;

      function getAdoDb(strAdoType){
      if (window.ActiveXObject){
         return new ActiveXObject(strAdoType);
      }
      else{
         return ActiveXObject(strAdoType);
      }
   }

   function showReports(){
      try{
         var strHtml ="";
         strHtml += "<table cellpadding=0 cellspacing=0 border=1 width= '100%' align=center>";
         strHtml += "<td><Font face ='tahoma'>S No</b></td>"
         strHtml += "<td><Font face ='tahoma'>Roll Number</b></td>"
         strHtml += "<td><Font face ='tahoma'>Name</b></td>"
         strHtml += "<td><Font face ='tahoma'>Maths</b></td>"
         strHtml += "<td><Font face ='tahoma'>Physics</b></td>"
         strHtml += "<td><Font face ='tahoma'>Chemistry</b></td>"
         strHtml += "<td><Font face ='tahoma'>Total</b></td>"
         strHtml += "<td><Font face ='tahoma'>Percentage</b></td>"
         strHtml += "<td><Font face ='tahoma'>Division</b></td>"

         //Database Connection
         var conn = getAdoDb("ADODB.Connection");
         conn.open(conn_str, "",   "");

         //Recordset
         var rs = new ActiveXObject("ADODB.Recordset");
         strQuery = "SELECT * FROM "+tableName+" WHERE ((("+tableName+".Name) Like '%" +searchStr+"%'))";
         document.write(strQuery);
         //strQuery = "SELECT Sheet1.Date, Sheet1.Name, Sheet1.Group, Sheet1.Details FROM SampleTable";
         rs.open(strQuery, conn, adOpenDynamic, adLockOptimistic);

         if(!rs.bof){
            rs.MoveFirst();
            while(!rs.eof) {
               strHtml += "<tr>";
               strHtml += " <td><Font face ='tahoma'>" + rs.fields(0).value + "</font></td>";
               strHtml += " <td><Font face ='tahoma'>" + rs.fields(1).value + "</font></td>";
               strHtml += " <td><Font face ='tahoma'>" + rs.fields(2).value + "</font></td>";
               strHtml += " <td><Font face ='tahoma'>" + rs.fields(3).value + "</font></td>";
               strHtml += " <td><Font face ='tahoma'>" + rs.fields(4).value + "</font></td>";
               strHtml += " <td><Font face ='tahoma'>" + rs.fields(5).value + "</font></td>";
               strHtml += " <td><Font face ='tahoma'>" + rs.fields(6).value + "</font></td>";
               strHtml += " <td><Font face ='tahoma'>" + rs.fields(7).value + "</font></td>";
               strHtml += " <td><Font face ='tahoma'>" + rs.fields(8).value + "</font></td>";
               strHtml += "</tr>";

               rs.MoveNext();
            }
         }
      else{
            //No Records.
            strHtml += "<tr colspan=4><td align=center><font color=red>No Records.</font></td></tr>";
         }
         conn.close();
         strHtml += "</table>";
         document.write(strHtml);
      }catch(ex){
      alert(ex.message);
   }
}
</script>
</head>    
</div>
</body>
</html>
user3103991
  • 407
  • 1
  • 8
  • 13
  • 1
    So why don't you post the code that is working in IE9 – adeneo Dec 27 '13 at 20:44
  • i want to but i am not able to post in because of the indentation problem here in Stackoverflow, Its not allowing me. – user3103991 Dec 27 '13 at 20:53
  • There's no indentation problem, just copy paste the code, select it and click the "code" button in the editor ? – adeneo Dec 27 '13 at 20:58
  • Ya got it..:) I Just added the code along with the post.. Please check. – user3103991 Dec 27 '13 at 21:08
  • What is the error message that yo're getting and at what line? – Yuriy Galanter Dec 27 '13 at 21:35
  • error: Automation server cant create object.. you can take this code and check in IE8 you will get the same.. i think its in the call of shoeReports() – user3103991 Dec 27 '13 at 21:39
  • You may find [this link](http://stackoverflow.com/questions/9777038/read-and-write-to-an-access-database-using-javascript) notable. – Siva Tumma Dec 29 '13 at 07:46
  • Possible duplicate of [IE8 ADO warning when opening a record set with JavaScript](http://stackoverflow.com/questions/10369900/ie8-ado-warning-when-opening-a-record-set-with-javascript) – Paul Sweatte Jul 21 '16 at 07:51

0 Answers0