473,396 Members | 2,016 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do I get to the fieldnames of a table?

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.
Jul 19 '05 #1
7 3264
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..
Jul 19 '05 #2
an*******@discussions.microsoft.com wrote:
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

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #3
aa wrote:
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

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #4
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

-----Original Message-----
an*******@discussions.microsoft.com wrote:
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 thefield names, right?

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my Fromheader is my spam trap, so I don't check it very often. You will get aquicker response by posting to the newsgroup.
.

Jul 19 '05 #5
an*******@discussions.microsoft.com wrote:
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

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 19 '05 #6
Hi Bob

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

Something new learned everyday!
Jul 19 '05 #7
Thank you very much, everybody. Most helpful

andre
Jul 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Josep | last post by:
Hi, I'd like to poll a database and get the table contents, as well as the field names from that table. I've been to php.net but this time I cannot find something helpful. I can get the data,...
4
by: Little PussyCat | last post by:
Hello, I have had a request, one of our tables is used as a report and I have been asked that all fieldnames for months have dashes in them, like Jan-05 instead of Jan05 and so on... Now what...
3
by: Beren | last post by:
Hello, I have an sproc to query a couple of tables, that have the same fieldnames, for example DateCreated. ------------------------------------- Select a.* , b.* From tablea a Join table b...
6
by: Miles Keaton | last post by:
Is there a simple way to list fieldnames in a table, from PHP? When on the command-line, I just do \d tablename But how to get the fieldnames from PHP commands? ...
1
by: meltedown | last post by:
This is a function that returns the names a table field on a pgsql database $skips is simply the field names that will be left out of the result. This function acts differently on two different...
7
by: MLH | last post by:
I use this to list table fieldnames to the debug window. Can it be modified to perform similar objective for saved query objects? Would it be best to trash this completely and write a procedure...
1
by: MLH | last post by:
What might a FN look like to put the following lines in if such FN accepted an array of desired fieldnames and fieldtypes? I would like to have the functional lines that follow in a FN that...
6
by: Gerrit | last post by:
Hello, I try to display the fieldnames and the primary key of a table, with this code: using System; using System.Collections.Generic; using System.Text; using System.Data; using...
2
by: john | last post by:
In the query builder I made an edit-query in which I have linked table A to table B on IDnr. For every record that matches I want 5 fields of table A to get the values of corresponding fields in...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.