How to handle Null Author Library: Eastern spider (rpm)
For beginners, there is a touchless thing to deal with the NULL data in the database. In this article article, we will talk about null, you will know how to know a value is null, which functions can or not Can handle NULL
First, we must know that in VBScript, Variant is the only data type, which may feel a bit unhearer for those program developers who are familiar with other languages. The advantage of using Variant is that it is quite elastic because Variant can store any data type, such as an integer, string, datetime, and even objects and arrays. However, elasticity is necessary to pay, because the specified Variant may be much more than the memory used by the specified special data type.
There are still two very special subtypes (Subty): EMPTY and NULL in the Variant Data Type, in fact, it is not appropriate, because they don't store some values, when a variable's data subtype is EMPTY Or NULL, their value is EMPTY or NULL
EMPTY
A variable is after being declared, but before it is specified, this variable's information subtype is EMPTY. In other words, EMPTY is equivalent to "not initialized", let's take a look at the example below.
DIM VARTEST RESPONSE.WRITE TYPENAME (VARTEST)
Its execution should be EMPTY, so EMPTY can be said to be a variable initial subscriber type and initial value, and EMPTY simply represents a state of a variable, try the example below.
DIM VARTEST RESPONSE.WRITE CLNG (VARTEST) Response.write CSTR (VARTEST)
The first line of the first line will be displayed 0 because EMPTY is indicated as an integer is 0, and the result of the second line will not be displayed because the EMPTY is EMPTY when it is represented as a string, or it can be said to be a length Zero string
When a variable is specified, it is no longer EMPTY, which will be other subtypes, depending on the type of information, of course, you can also use the Empty this key to change this variable back to EMPTY Types of
Vartest = EMPTY
There are two ways you can judge whether a variable is EMPTY
IF VARTEST = Empty Ten Response.write "The Variable IS Empty." Endiff
Or
If ISEMPTY (VARTEST) THEN RESE.WRITE "The Variable IS Empty." Endiff
NULL
NULL is very similar to EMPTY, but Empty means that Empty represents a variable has not been initialized, that is, the value has not been given any value, and a variable is NULL only after you specify it to null. The most often encountered NULL should be when the database is dealt, when there is no information in one field, it is NULL.
Specifying and determining NULL method is similar to EMPTY
Vartest = NULL
However, you can only use the isnull () function to determine NULL, because NULL represents the illegal information, you can try the following examples
DIM VARTEST VARTEST = NULL IF VARTEST = NULL THEN RESE.WRITE "The Variable Has A Null Value." END IF
The result of the execution does not display the Variable Has A Null Value. To determine if a variable is null, you should use the isnull () function
DIM VARTEST VARTEST = NULL IF INULL (VARTEST) THEN RESE.WRITE "The Variable Has A Null Value." Endiff
When you are processed by NULL taken from the database, you must pay attention, because NULL represents illegal information, null may create some trouble when some functions are processed, NULL may create some troubles. For example, DIM VARTEST VARTEST = NULL VARTEST = CLNG (Vartest)
Executive result You will see the "Invalid Use of Null" error message, then look at the example below
DIM VARTEST DIM LNGTEST VARTEST = NULL LNGTEST = 2 Vartest Response.write TypeName (LNGTEST)
You will find that NULL plus 2 or null therefore, when you get the information from the database, you should use Isnull () to determine if the field is null, then properly process, for example
LNGQTY = ORS ("Quantupy") if isnull (lngqty) Then Lngqty = 0 end if
I hope this article helps you!