Posted By

kashif21 on 03/26/11


Tagged

javascript sql query using


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

notturnale


sql query using javascript


 / Published in: JavaScript
 

  1. function dblookup()
  2. {
  3. var myConnect = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=d:\\sdi.mdb";
  4.  
  5. var ConnectObj = new ActiveXObject("ADODB.Connection");
  6. var RS = new ActiveXObject("ADODB.Recordset");
  7. var sql="SELECT * FROM employeespulled WHERE empid='1';";
  8.  
  9. ConnectObj.Open (myConnect);
  10. RS.Open(sql,ConnectObj,adOpenForwardOnly,adLockReadOnly,adCmdText);
  11.  
  12. var fieldCount = RS.Fields.Count;
  13. alert("Field Count" + fieldCount);
  14. RS.Close();
  15. ConnectObj.Close();
  16. }
  17.  
  18. //////////////////////2nd methood//////////////////////////////////
  19. <html>
  20. <head>
  21.  
  22. <script language="JavaScript">
  23.  
  24. var cn = new ActiveXObject("SQLiteDb.Connection");
  25. if (typeof(cn)=="undefined" || cn==null)
  26. alert("Unable to create the connection object!");
  27. else
  28. alert("Connection object was successfully created!");
  29.  
  30. var strConn = "Database=db/test.db";
  31. function getdata(){
  32. cn.Open(strConn);
  33. var rs = new ActiveXObject("SQLiteDb.Recordset");
  34. var SQL = "SELECT CoName from Companies WHERE CoID=1";
  35. rs.Open(SQL, cn);
  36. alert(rs(0));
  37. rs.Close();
  38. cn.Close();
  39. }
  40. </script>
  41.  
  42. </head>
  43. <body>
  44.  
  45. <input type="button" value="Get data"
  46. onclick="getdata()">
  47. </body>
  48. </html>

Report this snippet  

You need to login to post a comment.