ASP 101 - Active Server Pages 101 - Web01
The Place ASP Developers Go!



Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates
ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash



 Top ASP 101 Stories Top ASP 101 Stories
Connections, Commands, And Procedures
What is ASP?
VBScript Classes: Part 1 of N

QUICK TIP:
Using Access Hyperlink Fields From ASP
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates


Quick Tips


Reference Recordset Fields by Any Name

When writing ASP scripts that deal with databases, you often aren't fortunate enough to have a database whose naming conventions make sense given the context of your script. While it might be obvious that something named first comes before something named last, do the hypothetical fields store someone's first and last name or the date of their first and last transaction?

There's no need to carry this ambiguity through into the recordsets you use in your ASP code. You can easily reference the fields by more accurate names to make your code more readable. The secret is simply in the SQL command you use.

SELECT first, last, date FROM tblEmployee

might get the job done, but

SELECT first As FirstName, last As LastName, date As DateOfBirth FROM tblEmployee

leaves no question what those fields actually contain and will make the rest of your code that deals with them that much easier to understand. Especially since you can use the new aliases when requesting the fields from your recordset.

Another time when this technique can be extremely valuable is when you don't know what a field would otherwise be called. This is often the case when you're doing a calculation of some sort. For example...

SELECT Count(*) FROM tblEmployee

might return a count of all the employees, but you'll be forced to reference it like this:

rstEmployee.Fields(0).Value

If you instead use...

SELECT Count(*) As EmployeeCount FROM tblEmployee

you can more acurately indicate what you're trying to retreive from the recordset:

rstEmployee.Fields("EmployeeCount").Value


Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers