How do I get to the fieldnames of a table?

G

Guest

How do I get to the fieldnames of a table in a recordset?

I have a recordset which I output into HTML.
And on data from certian columns I need to perform different actions.

I would like to use the fieldnames rather then theit sequential numbers, to
avoid the need to re-do the code if another field is inserted into the
table.
 
G

Guest

Hi

See the sample below..

If you need to see all fields then you should have a query
like "select * from TABLE_NAME"

rs is the recordset returned from the SQL query

for each x in rs.fields
response.write(x.name)
response.write(" = ")
response.write(x.value)
next


Hope this helps..
Kev..
 
B

Bob Barrows

Hi

See the sample below..

If you need to see all fields then you should have a query
like "select * from TABLE_NAME"

I'm sure you meant to say
"select * from TABLE_NAME where 1=2"

so the user would avoid returning all the data in the table just to get the
field names, right?

Bob Barrows
 
B

Bob Barrows

aa said:
How do I get to the fieldnames of a table in a recordset?

I have a recordset which I output into HTML.
And on data from certian columns I need to perform different actions.

I would like to use the fieldnames rather then theit sequential
numbers, to avoid the need to re-do the code if another field is
inserted into the table.

You will never have to do this if you follow the good coding practice of
always explicitly naming the columns you wish your queries to return,
instead of using "Select *". Your queries will execute faster if you do this
since you avoid an extra trip to the database which ADO needs to make when
selstar is used.

Bob Barrows
 
G

Guest

Indeed i did.. My Apologies..

But since he/she doesn't know the names of the headers the
select could be changed to
"select top 1 * from Products"

this will be a minimum hit to the db but return the
information needed
 
B

Bob Barrows

Indeed i did.. My Apologies..

But since he/she doesn't know the names of the headers the
select could be changed to
"select top 1 * from Products"

this will be a minimum hit to the db but return the
information needed

"Top 1" will be slower (it still returns unneeded data) than using "WHERE
1=2" (which does not require using the field names).

Bob Barrows
 
K

Kev..

Hi Bob

I see your point.. Using your way just returns an empty
recordset...

Something new learned everyday!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top