Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 11th, 2003, 07:47 PM
Authorized User
 
Join Date: Jul 2003
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default Help with Recordsets and Databases

If I was using a SQL database and was running a query on my ASP page like SELECT * FROM CLIENTS and wanted to output the whole thing, and did not know the table field names how would I do that. I have a web site where you can dynamically generate a query, by selecting the table, then the fields you want, and then under what parameters to pull the information. But if the user selects "All" on the field options page how do I output the fields. Any thing would help thanks.
 
Old November 12th, 2003, 04:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

I assume you would be using an ADO recordset to get the query results? If so, the recordset object has a Fields collection which you can iterate through. If say, you wanted to output the field names as column headers you could use the Name property of each field, then the actual data would be output using the Value property. Something like this:
Code:
' code here to run query, get recordset back and check it has data
Dim fld
Response.Write "<table><tr>"
' write out col headings
For Each fld in recordsetName.Fields
    Response.Write "<td>"
    Response.Write fld.Name
    Response.Write "</td>"
Next
Response.Write "</tr>"

' write out col data
Do While Not recordsetName.EOF
    Response.Write "<tr>"
    For Each fld in recordsetName.Fields
        Response.Write "<td>"
        Response.Write fld.Value ' maybe deal with Nulls here too
        Response.Write "</td>"
    Next
    Response.Write "</tr>"
    recordsetName.MoveNext
Loop
hth
Phil





Similar Threads
Thread Thread Starter Forum Replies Last Post
Recordsets JezLisle Access VBA 11 July 17th, 2007 03:47 AM
Help with Recordsets voskoue Access VBA 1 January 23rd, 2007 08:36 AM
Recordsets on Split (Linked) Databases davest Access VBA 1 October 20th, 2004 01:33 PM
Need help with recordsets chacquard Access VBA 5 June 21st, 2004 11:58 PM
Recordsets bph Access VBA 17 February 17th, 2004 03:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.