home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _215880a18e2849927b21fbd2ac4151a3 < prev    next >
Text File  |  2004-06-01  |  3KB  |  77 lines

  1. <%@ LANGUAGE = PerlScript%>
  2. <html>
  3. <head>
  4. <meta name="GENERATOR" content="Tobias Martinsson">
  5.  
  6. <title>Looping The Fields Collection</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) Fields Collection</H3>
  25. The Fields Collection of the Recordset object contains Field objects. In plain English, each Field object represents a record that was returned from a query against a database. In the example to follow, the database table "Orders" is queried to return all columns (the asterisk (*) represents that) and all records. Instead of an asterisk, however, you may specify the names of the columns to return, and the rules are simple: multiple columns are separated by comma(for example, "Firstname, Lastname"), and column-names that contain spaces are enclose within square brackets(for example, "[some column]").
  26.  
  27. In a database table, each Record or entry has a given set of columns for which it must provide values. The Field object is the object representation of the column names and values that was provided and is located within the database. You can use the "in"-method of the Win32::OLE module to easily loop each returned Field object to easily present its column-name and set value.
  28.  
  29.     <p>
  30.     <%
  31.         # Create an instance of a Recordset object
  32.         #
  33.     $rst = $Server->CreateObject("ADODB.Recordset");
  34.  
  35.         # Open it by providing an SQL query as first parameter
  36.         # and a System DSN as the second parameter
  37.         #
  38.     $rst->Open( "SELECT * FROM Orders", "ADOSamples" );
  39.     
  40.         # While the Recordset has not reached End Of file ...
  41.         #
  42.     while( ! $rst->{EOF} ) {
  43.  
  44.             # Each field object is put into the variable $field
  45.             # and then accessed within the loop
  46.             #
  47.             foreach my $field (Win32::OLE::in($rst->Fields)) {
  48.                 $Response->Write("The name is ");
  49.                 $Response->Write($field->{Name});
  50.                 $Response->Write(" and the value is ");
  51.                 $Response->Write($field->{Value});
  52.             $Response->Write("<BR>");
  53.             }
  54.         $rst->Movenext();
  55.     }
  56.  
  57.         $rst->Close();
  58.         undef($rst);
  59.     %>
  60.  
  61. <!-- +++++++++++++++++++++++++++++++++++++
  62. here is the standard showsource link - 
  63.     Note that PerlScript must be the default language --> <hr>
  64. <%
  65.     $url = $Request->ServerVariables('PATH_INFO')->item;
  66.     $_ = $Request->ServerVariables('PATH_TRANSLATED')->item;
  67.     s/[\/\\](\w*\.asp\Z)//m;
  68.     $params = 'filename='."$1".'&URL='."$url";
  69.     $params =~ s#([^a-zA-Z0-9&_.:%/-\\]{1})#uc '%' . unpack('H2', $1)#eg;
  70. %>
  71. <A HREF="index.htm"> Return </A>
  72. <A HREF="showsource.asp?<%=$params%>">
  73. <h4><i>view the source</i></h4></A>  
  74.  
  75. </BODY>
  76. </HTML>
  77.