home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _28b1f07ca9e983622975ed111adda69b < prev    next >
Text File  |  2000-03-15  |  2KB  |  56 lines

  1. <%@ LANGUAGE = PerlScript%>
  2. <html>
  3. <head>
  4. <meta name="GENERATOR" content="Tobias Martinsson">
  5.  
  6. <title>ADO Record Counting</title>
  7. </head>
  8. <body>
  9. <BODY BGCOLOR=#FFFFFF>
  10.  
  11. <!-- 
  12.     ActiveState PerlScript sample 
  13.     PerlScript:  The coolest way to program custom web solutions. 
  14. -->
  15.  
  16. <!-- Masthead -->
  17. <TABLE CELLPADDING=3 BORDER=0 CELLSPACING=0>
  18. <TR VALIGN=TOP ><TD WIDTH=400>
  19. <A NAME="TOP"><IMG SRC="PSBWlogo.gif" WIDTH=400 HEIGHT=48 ALT="ActiveState PerlScript" BORDER=0></A><P>
  20. </TD></TR></TABLE>
  21.  
  22. <HR>
  23.  
  24. <H3>ActiveX Data Objects (ADO) Record Counting</H3>
  25. Counting the number of records in a Recordset is something many find troublesome at first. The solution to why it sometimes return -1 instead of an accurate count is very simple. In order to avoid -1, you must use a cursor that can move all the way to the end of the Recordset and then back. Unless specified, the cursor will default to a cursor that moves only forward in the Recordset, thus can not determine the count. In this example, we use a Keyset cursor, which is a lightweight cursor that can move both forward and backward. When the database connection is open, the Recordset will contain the number of available records matching the query in its RecordCount-property.
  26.  
  27.     <p>
  28.     <%
  29.     my $adOpenKeySet_CursorType = 1;
  30.  
  31.     $rst = $Server->CreateObject('ADODB.Recordset');
  32.     $rst->Open('SELECT * FROM Orders', 'ADOSAMPLES', $adOpenKeySet_CursorType);
  33.  
  34.     $Response->Write("There are ".$rst->{RecordCount}." records in the Recordset");
  35.  
  36.         $rst->Close(); # Close the recordset
  37.         undef($rst); # Destroy the object
  38.     %>
  39.  
  40. <!-- +++++++++++++++++++++++++++++++++++++
  41. here is the standard showsource link - 
  42.     Note that PerlScript must be the default language --> <hr>
  43. <%
  44.     $url = $Request->ServerVariables('PATH_INFO')->item;
  45.     $_ = $Request->ServerVariables('PATH_TRANSLATED')->item;
  46.     s/[\/\\](\w*\.asp\Z)//m;
  47.     $params = 'filename='."$1".'&URL='."$url";
  48.     $params =~ s#([^a-zA-Z0-9&_.:%/-\\]{1})#uc '%' . unpack('H2', $1)#eg;
  49. %>
  50. <A HREF="index.htm"> Return </A>
  51. <A HREF="showsource.asp?<%=$params%>">
  52. <h4><i>view the source</i></h4></A>  
  53.  
  54. </BODY>
  55. </HTML>
  56.