Go Back   DeveloperBarn Forums > Programming & Scripting > ASP Development

Sponsored Links

Discuss "How to retrieve unknown recordset field names in table?" in the ASP Development forum.

ASP Development - Learn coding practices and tips to get the best out of your Active Server Pages (ASP). The Classic ASP forum is for ASP/VBScript and ASP/JScript applications.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old July 30th, 2008, 10:38 AM
BLaaaaaaaaaarche's Avatar
Administrator


 
Join Date: Mar 2008
Posts: 55
Thanks: 10
Thanked 7 Times in 5 Posts
Rep Power: 1
BLaaaaaaaaaarche is on a distinguished road

Awards Showcase
HTML & CSS Classic ASP 
Total Awards: 2

Default How to retrieve unknown recordset field names in table?

If I am looking to retrieve the field names in my table that are unkown, how would I write a loop to do so? For instance, if I have the following table:

Code:
Table: tblProducts
Fields:
ProductID
ProductName
ProductLocation
ProductType
The problem is, in the real world, I don't know those fields names and need a quick query to spit them out so I can build my query. Any ideas?
__________________
"You'll never be as perfect as BLaaaaaaaaarche."
Reply With Quote
Sponsored Links
  #2  
Old July 30th, 2008, 10:39 AM
jmurrayhead's Avatar
The Barnfather

 
Join Date: Mar 2008
Location: Reston, VA, USA
Posts: 820
Thanks: 20
Thanked 74 Times in 71 Posts
Blog Entries: 5
Rep Power: 3
jmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura aboutjmurrayhead has a spectacular aura about

Awards Showcase
Microsoft .Net Microsoft SQL Server Microsoft Windows Classic ASP 
Total Awards: 4

Default

Here's a quick sample:

Code:
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "... put your connection string here ..."
 
Set RS = Server.CreateObject("ADODB.RecordSet")
RS.Open "... put your tablename *or* SQL statement here ...", conn
 
Response.Write "<TABLE Border=1 CellPadding=5>" & vbNewLIne 
Response.Write "<TR>" & vbNewLine
' RS.Fields is the collection of fields associated with the recordset...
' The count given is correct, but since the fields are numbered
' starting at zero, we have to subtract one to get the maximal field number:
For fnum = 0 To RS.Fields.Count-1
   ' Naturally, each element in the Fields collection is 
   ' an ADODB.Field object. And the Field object has various
   ' properties, including...ta da!...its Name:
   Response.Write "<TH>" & RS.Fields(fnum).Name & "</TH>" & vbNewLine
Next
Response.Write "</TR>" & vbNewLine
 
RS.Close
conn.Close
%> 
__________________
jmurrayhead
If you agree with me... click the icon!
If my post solved your problem, click the button in the lower right-hand corner of the post.

Join our Folding team: DeveloperBarn Folding
Reply With Quote
The Following User Says Thank You to jmurrayhead For This Useful Post:
BLaaaaaaaaaarche (July 30th, 2008)
  #3  
Old August 10th, 2008, 08:33 AM
Shadow Wizard's Avatar
Ask Me About Dragons :D

 
Join Date: Jul 2008
Posts: 23
Thanks: 0
Thanked 4 Times in 4 Posts
Blog Entries: 1
Rep Power: 1
Shadow Wizard is on a distinguished road

Awards Showcase
Microsoft .Net Classic ASP JavaScript 
Total Awards: 3

Default

if all you need is the field names, add "Where 1=0" to the SQL to avoid
getting all the records. in big tables it would waste pretty much time.
Reply With Quote
The Following User Says Thank You to Shadow Wizard For This Useful Post:
BLaaaaaaaaaarche (August 10th, 2008)
Reply

  DeveloperBarn Forums > Programming & Scripting > ASP Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Forms] Field that is a link (rs) and/or text field question Rebelle ASP Development 14 August 12th, 2008 08:43 AM
Create History Table / Outcome results Rebelle Database Design Help 9 July 1st, 2008 08:33 AM
Help with asp display / recordset (troubleshoot) Rebelle ASP Development 27 June 30th, 2008 11:19 AM
retrieve values todd2006 SQL Development 5 June 19th, 2008 01:46 PM
importing file names based on extension sbenj69 Microsoft Access 1 April 11th, 2008 12:56 AM


All times are GMT -4. The time now is 05:42 PM.



Content Relevant URLs by vBSEO 3.2.0