Name and number of fields used by ASP to read a table
The recordst object Stores Table records in a two-dimensional array. In fact, each row of the recordset object belongs to the fields set, and each item of the fields set is a field object, therefore, we can use the Count attribute of the fields set to read the number of fields in the table, and then use the name and value attributes of the Field object to read the field name and field data respectively, because value is the default attribute of the fields set, the following four statements are the same: 1 objrs (I) 2 objrs (I ). value 3 objrs. fields (I) 4 objrs. fields (I ). value
<% Option explicit %>
<! -- # Include file = "common/Conn. asp" -->
<%
Dim objrs
Dim fieldcount
Dim I
Dim m
Dim N
Dim temp
Set objrs = objconn.exe cute ("select * from [user]")
'Field and
Fieldcount = objrs. Fields. Count
'Output fields and
Response. Write ("Total number of fields" & fieldcount & "<HR> ")
%>
<Table>
<Tr>
<! -- Name of the output field -->
<%
For I = 0 to fieldcount-1
Response. Write ("<TH>" & objrs. Fields (I). Name & "</Th> ")
Next
%>
<! -- Output the data of fields in the table -->
<%
Do while not objrs. EOF
Temp = "<tr>"
'---- Looping the value of a field instead of its name
For n = 0 to fieldcount-1
Temp = temp & "<TD>" & objrs. Fields (N). Value & "</TD>"
Next
'---- End
Response. Write temp & "</tr>"
Objrs. movenext
Loop
%>
</Tr>
</Table>
<%
Objrs. Close
Set objrs = nothing
Objconn. Close
Set objconn = nothing
%>