Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

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


Using Data - Page 4

November 27, 2000

Stuffing Data into a Variable

Sometimes we don't need the data to go directly to the page, in which case we can save the information into a variable. For example, we may need to perform some string manipulation or validation prior to building the page.
VarNameFirst = ORSp("PeopleNameFirst")
The code on the above line stores the data into a variable for later use. This must be performed within ASP delimiters, since HTML lacks capacity to use variables.

The most common mistakes are:

  • Attempting to perform this operation in HTML, outside of ASP
  • Wrong RS name or wrong Field name
  • Misspelled Field Name (very common error)

Using Data in an Expression

Data retrieved by ADO can be used directly in an expression. The pseudo-code listings below show examples:
If ORSp("NameFirst")="Enrico" then
  ' code for Enrico
End If
In the above code we use the data in a field of the current record of the oRSp recordset as the text to compare against the word "Enrico." A similar test is performed in the code below to determine if it is time to end the looping.
Do while NOT oRSp("NameFirst")="Enrico"
  ' code for people OTHER then Enrico
  oRSp.MoveNext
Loop

If oRSp("Member") then
  ' code for members
Else
  ' code for non-members
End If
In our last case we switch to retrieving data from a different field. The member field was established (at the time the database was designed) as of type True/False. Therefore it will return a value of true or false, which can be directly used as a whole expression. If the database contains true the code for members will be run.

The most common mistakes are:

  • Attempting to perform this operation in HTML, outside of ASP
  • Leaving the comparison sign (= or > or <) out of the expression
  • Writing expressions where the two sides of the comparison sign are of two different data types. For example, "Joe" should not be compared to "2".
  • Wrong RS name or wrong Field name
  • Misspelled Field Name (very common error)
  • Errors in upper/lower case for data stores that are case sensitive
  • Quotes around numerical values

Using Data as an Argument in a Function

Data read by ASP-ADO can be used as an argument for another function. For example:
VarNameFirstLetter = Left(oRSp("PeopleNameFirst"),1)

VarPassword = lCase(oRSp("PeopleNameFirst"))

VarSpaceLocation = instr (oRSp("PeopleNameFirst")," ")
Although the above works, many coding shops prefer that you first read the data into a local variable. It is easier to read and maintain code without all of the quotes and parentheses.

The most common mistakes are:

  • Attempting to perform this operation in HTML, outside of ASP
  • Providing data from ASP-ADO which is of the wrong type for the argument
  • Wrong RS name or wrong Field name
  • Misspelled Field Name (very common error)
  • Not writing test code to handle a request that returns a NULL

Syntax for Simple Recordsets - Page 3
Beginning ASP Databases
Using Recordset Data - Page 5


Up to => Home / Authoring / ASP / BeginningASPDatabases




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers