![]() |
| |||||||
| Sponsored Links |
![]() | « Previous Thread | Next Thread » |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| ||||
| ||||
| 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
__________________ "You'll never be as perfect as BLaaaaaaaaarche." |
| Sponsored Links |
|
#2
| ||||
| ||||
| 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 |
| The Following User Says Thank You to jmurrayhead For This Useful Post: | ||
BLaaaaaaaaaarche (July 30th, 2008) | ||
|
#3
| ||||
| ||||
| 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. |
| The Following User Says Thank You to Shadow Wizard For This Useful Post: | ||
BLaaaaaaaaaarche (August 10th, 2008) | ||
![]() |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
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 |