Write out data to an html table using the NAME property.

Contributed by
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
September 01, 1999
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement
This is a demo shows how to take a Recordset and write out the data using the NAME property and all data associated with that Name.  This was something I ran across and found very useful.  Its very nice when presenting data in HTML. 


This is what the data looks like once its been selected and written out.
id EmailAddress Homepage
1 johndoe@blah.com http://www.someurl.com
2 blahman@blah.com http://www.someurl.com
3 Aperson@blah.com http://www.someurl.com
4 Jane@blah.com http://www.somewhere.com
5 henry@blah.com http://www.someURL.com

 


Here is the code that created the table presented above

<%@ Language = "VBScript"%>
<%
response.buffer = true
On Error Resume Next

strconn = "Driver={SQL Server};Description=connstring;SERVER=127.0.0.1;UID=loginid;PWD=password;DATABASE=some_db"

dim conn
dim rs
dim strID
dim strSql

set conn = server.createobject("adodb.connection")
set rs = server.createobject("adodb.recordset")
conn.open strconn

strSql = "SELECT tblWriteOutHeader.id, tblWriteOutHeader.EmailAddress, tblWriteOutHeader.Homepage" & _

" FROM tblWriteOutHeader" & _

" ORDER BY tblWriteOutHeader.id"

rs.open strsql, conn

%>

<% rs.movefirst %>

<html><head>
<title>Write out headers</title></head><body>

<TABLE BORDER="1" width="80%">

<TR>

'This section writes out the Names of the fields in the Recordset

<% For Each Field In RS.Fields %>

<TH>  

<% If Field.Name <> "ID" Then

response.write Field.name

End If %>  

</TH>

<% Next %>

</TR>

'This section writes out the DATA of the fields in the Recordset

<% Do While Not RS.EOF %>

<TR>

<% For Each Field In RS.Fields %>

<TD ALIGN=center>

<%If IsNull(Field) Then

Response.Write ""

Else

Response.Write Field.Value

End If %>

</TD>

<% Next

RS.MoveNext %>

</TR>

<% Loop %>

</TABLE>

<% 
Rs.Close
Set Rs = Nothing 
%>

<p>&nbsp;</p>
</body>
</html>
<%
conn.close
set conn = nothing
%>

 

blog comments powered by Disqus
ASP CODE ARTICLES

- ASP Forms
- ASP: The Beginning
- Getting Remote Files With ASP Continued
- Inbox and Outbox Manipulation in ASP
- Relational DropDownList Using VB.NET
- Ad Tracking URL Hits
- Use ViewState to display one record per page...
- Send Email using ASP.NET formatted in HTML
- ASP File Explorer
- ASP/XML Interview questions by Srivatsan Sri...
- Pressing RETURN won't submit the form
- This shows how you get the TEXT of a combo r...
- Group Data by Adrian Forbes
- Multiple checkbox select sample
- Multiple checkbox select with all values sam...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials