Home  |  Latest News  |  Contribute  |  F.A.Q.  |  Account  |  Scripts | About
Search ASPNut:
 
ASP Reference
Server Variables
ASP Glossary
Related Sites

Free Components

HTML Reference
Web Colors
Entities
CSS Level 1
Encode/Decode
Glossary

Our Sponsors
ASP Nuke CMS
Free Auctions
PHP 5 Script
Funktastic Blog
ULost Directory
Team Task

 

 

 

 

 

 

 

 

 

 

 

 

Common Pitfalls for ASP Developers
8/11/2003 - Kenneth W Richards

Today we are discussing common pitfalls to watch out for when developing in ASP.
Microsoft has strived to make their language easy to learn and easy to use but
they have failed to make it "idiot-proof".

Global vs. Local Variables

It is very easy to get confused when using global and local variables in a
script. By "local" here, we mean local to a function or subroutine definition.
A global variable is defined at the script level and may be accessed anywhere in
your script even within a function.

For this reason, it is easy to accidentally use a variable defined at the script-
level within a function without meaning to. In practice it is best to use no
script-level variables within your subroutines.

Another problem with variables is mis-typing a variable name. If you
accidentally type the wrong name for a variable, it will assume the empty value
which corresponds to a zero (0) for numbers, false for boolean and the empty
string.

To avoid this problem you should always use the Option Explicit
directive at the top of your scripts. This can only appear once (for all
included files) and must appear as the first statement in your script.

Option Explicit
<!-- #include file="somefile.asp" -->
....

Working with a Database

When working with a database, there are several problems that you will need to
watch out for. The first of which is the database connection string. This can
be difficult for beginners to understand when they are first starting ASP.
There are many different forms the connection string can take and each one is
specific to the type of database you are using.

For examples of ASP connection strings, we will refer you to this site which
lists a myriad of different connection strings:

ADO Connection String
Examples

Another thing to be careful of is when working with values returned from a
recordset. If the value that is returned in a database field is the database
special value "NULL", it can cause all sorts of problem when used in expressions
in your code. Basically, "NULL" will not automatically convert to anything.

ASP has a special work-around which will allow you to convert all NULLs to an
empty string by using the syntax:

sValue = rs.Fields("Field1").Value & ""

By concatenating an emtpy string to the database field, you will convert null
values to an empty string. If the field has a value, it will be converted to a
string by this expression. Another alternative is to test for null values using
the IsNull function.

If IsNull(rs.Fields("Field1").Value Then
	sValue = "n/a"
Else
	sValue = rs.Fields("Field1").Value
End If

<< Return Home

Orvado Technologies

ASP Nuke CMS
Free Open Source
Content Manager
HomeFix Boards
Home Remodeling
Message Boards

Contact Us | Contribute | About | Site Map



"Watching football is like watching pornography. There's plenty of action, and I can't take my eyes off it, but when it's over, I wonder why the hell I spent an afternoon doing it." - Luke Salisbury

©2010 San Diego Web Design - Orvado Technologies, All Rights Reserved
ASP Nut provides articles and reference documentation for Active Server Page developers.