ADO Samples

AbsolutePosition and CursorLocation Properties Example (JScript)

This example demonstrates how the AbsolutePosition property can track the progress of a loop that enumerates all the records of a Recordset. It uses the CursorLocation property to enable the AbsolutePosition property by setting the cursor to a client cursor.

<!-- BeginAbsolutePositionJS -->
<% @LANGUAGE="JScript" %>
<!-- Include file for JScript ADO Constants -->
<!--#include File="adojavas.inc"-->

<html>

<head>
<title>AbsolutePosition and CursorLocation Properties Example (JScript)</title>
<style>
<!--
BODY {
   font-family: 'Verdana','Arial','Helvetica',sans-serif;
   BACKGROUND-COLOR:white;
   COLOR:black;
    }
.thead2 {
   background-color: #800000; 
   font-family: 'Verdana','Arial','Helvetica',sans-serif; 
   font-size: x-small;
   color: white;
   }
.tbody { 
   text-align: center;
   background-color: #f7efde;
   font-family: 'Verdana','Arial','Helvetica',sans-serif; 
   font-size: x-small;
    }
-->
</style>
</head>

<body>
<h1>AbsolutePosition and CursorLocation Properties Example (JScript)</h1>
<%
   var Connect = "Provider=sqloledb;Data Source=" +
   Request.ServerVariables("SERVER_NAME") + ";" +
   "Initial Catalog=Northwind;User Id=sa;Password=;"
   
   // Open a recordset on the Employee table using
   // a client-side cursor to enable AbsolutePosition property.
   var RsEmployee = Server.CreateObject("ADODB.Recordset");
   RsEmployee.CursorLocation = adUseClient;
   RsEmployee.Open("employees", Connect, adOpenStatic, adLockOptimistic, adCmdTable);
   
   var strMessage;      // used to build up each row of the table before writing to document.

   // Write beginning of table to the document.
   Response.Write('<table border="0" align="center">');
   Response.Write('<tr class="thead2">');
   Response.Write("<th>AbsolutePosition</th><th>Name</th><th>Hire Date</th></tr>");
   
   while (!RsEmployee.EOF)
   {
      strMessage = "";
         
      // Start a new table row.
      strMessage = '<tr class="tbody">';
            
      // First column in row contains AbsolutePosition value.
      strMessage += "<td>" + RsEmployee.AbsolutePosition + "</td>"
               
      // First and last name are in first column.
      strMessage += "<td>" + RsEmployee.Fields("FirstName") + " ";
      strMessage += RsEmployee.Fields("LastName") + " " + "</td>";
            
      // Hire date in second column.
      strMessage += "<td>" + RsEmployee.Fields("HireDate") + "</td>";
            
      // End the row.
      strMessage += "</tr>";
         
      // Write line to document.
      Response.Write(strMessage);
            
      // Get next record.
      RsEmployee.MoveNext;
   }
   
   // Finish writing document.
   Response.Write("</table>");

   // Close table.
   RsEmployee.Close;
%>

</html>
<!-- EndAbsolutePositionJS -->

See Also

AbsolutePosition Property | CursorLocation Property | Recordset Object