www.webdeveloper.com
Results 1 to 3 of 3

Thread: Get Total number of records from MSAccess DataBase

  1. #1
    Join Date
    Mar 2009
    Posts
    19

    Get Total number of records from MSAccess DataBase

    Hi everyone,

    I have problem for getting the total number of records (Count) from MS-Access DataBase. I used the below code, any help given would be greatly appreciated. Please find the code below:

    Code:
              function findcrinf()
               {
                 var globe = null;
                 globe = new SGWorld();
    
                 var countree = document.all["countname"].value;
                 alert(countree);
    
                 var cn = new ActiveXObject("ADODB.Connection");
                 //Microsoft.ACE.OLEDB.12.0
                 //Microsoft.Jet.OLEDB.4.0
                 
                 var strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source = E:\\FramesTemplates\\troupdatabase.mdb;Persist Security Info=False";
                 cn.Open(strConn);
                 alert(strConn);
    
                 var eot = "select count(*) from troupinf";
                 alert(eot.value);
                 var i;
    
               for(i=0; i<=eot; i++)
                { 
                 var rs = new ActiveXObject("ADODB.Recordset");
                 var SQL = "Select * From troupinf where contry ='"+countree+"'";
                 alert(SQL);
                    
                  var xcord;
                  rs.Open(SQL, cn, 1, 3);
                  xcord = rs.Fields("xcoord").value;
                  alert(xcord);
    
                  var ycord;
                  ycord = rs.Fields("ycoord").value;
                  alert(ycord);
    
                  var zcord;
                  zcord = rs.Fields("zcoord").value;
                  alert(zcord);
    
                  var troupinfo;
                  troupinfo = rs.Fields("tropinfor").value; 
                  alert(troupinfo);
    
                  var dateinf;
                  dateinf = rs.Fields("datetoday").value;
                  alert(dateinf);
    
                  var timeinf;
                  timeinf = rs.Fields("timetoday").value;
                  alert(timeinf);
     
                  alert("Record Found");
     
                  var labelPos = new SGCoord3D(xcord, ycord, zcord);   
                  var label = globe.creator.createLabel(labelPos,"Troop1",troupinfo);
                              globe.root.appendChild(label);
                              globe.navigate.flyTo(label);
                  eot++;
                 }
    
                 rs.Close();
                 cn.Close(); 
    
               }
    Thanks & Regards,
    Sharat
    Last edited by sharat80; 08-13-2009 at 06:32 AM.

  2. #2
    Join Date
    Aug 2009
    Posts
    593
    Just an observation but:

    Code:
    var eot = "select count(*) from troupinf";
    You are assigning a string to eot and not actually querying the database.

  3. #3
    Join Date
    Mar 2009
    Posts
    19
    For getting the total number of records in the database I used the below code:

    Code:
          function getrows()
               {
                 var NumRows;
                 var query = "SELECT Count(*) AS NumRows FROM troupinf";
                 myStatement.execute(query);
    	     myStatement.nextRow();
                 var row = myStatement.getRow();
    	     this.getField("counter").value = row[NumRows].value;
                 alert(NumRows);
               }
    In above code am getting error: myStatement is undefined. I need to get the total number of rows in a table and need to pass each field value to the javascript variable. Could you plz find the error in above code and tell me any approach for doing this task.

    Thanks & Regards,
    Sharat.

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