Name and number of fields used by ASP to read a table

Source: Internet
Author: User

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
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.