473,785 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3287
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*******@discu ssions.microsof t.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*******@disc ussions.microso ft.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*******@discu ssions.microsof t.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
11335
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, and retrieve it into an array noproblem. I can get the data+fieldnames and put it into a list.
4
2018
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 we have is a CURSOR which loops through all values in another table generating these fieldnames, like 'Jan-05', Feb-05' etc.. Then the table definition is modified so these months display as fieldnames.
3
1988
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 On b.keyfield = a.keyfield -------------------------------------
6
4707
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? ---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.org so that your message can get through to the mailing list cleanly
1
1639
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 servers Both servers have PHP Version 4.3.10-10ubuntu4.3 AND PostgreSQL(libpq) Version 7.4.6 On one server, the function acts as expected, returning an array with the field names. On the other server, some of the field names come up 6
7
1874
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 for queries from scratch? Private Sub ListFieldsBttn_Click() '********************************************* ' Prompt user for the table name. List the ' s in the immediate window. '*********************************************
1
1264
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 accepted an array of data that looked like this: "VehicleJobID", dbLong "WannaBill", dbBoolean 10 If TableOrQueryExists("", "TempTable") Then DoCmd.DeleteObject acTable, "TempTable"
6
2132
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 System.Data.Odbc;
2
1482
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 table B. I'm able to make this query but only by typing the table B fieldnames in the 'change to'-row. Is there some easy way to drag those fieldnames to that row or another way to make this easier? Thanks, john
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9489
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10162
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9959
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.