How to deal with the database Null (z)

  How to deal with the database Null 
  Author: Oriental spider (to) 

  For beginners, in dealing with the Null database data types is a bit troublesome thing, in this article we will talk about the article Null, you will know how that is a Null value, which may or may not function handling Null 

  First, we must know that in VBScript, is the only one Variant data types, those who are already familiar with the development of programs in other languages, may feel a bit unaccustomed.    Variant use of the benefits of their considerable flexibility because Variant can store any data type, for example, integer, string, date, time, including arrays and objects.    However, flexibility is a price to pay, because the designated Variant than might be designated by the special data types to use much more memory 

  In the Variant data types there are two very special sub-type (Subtype): Empty and Null, in fact that may not be appropriate sub-type, because they do not store some value, when a variable is the type of information Empty or Null, and their value is Empty or Null 

Empty

  In a variable is declared, but its been designated a value before the variables in the types of information is Empty, in other words, the equivalent Empty "has not initialize", we take a look at the following example 

  Dim varTest 
  Response.Write TypeName (varTest) 

  Results for its implementation should be Empty, Empty can be said to be a variable of the initial data types and the initial value of a variable Empty only on behalf of the state, try the following example 

  Dim varTest 
  Response.Write CLng (varTest) 
  Response.Write CStr (varTest) 

  The first line program will show 0 as Empty been said that when the time for the integer 0, the second line will be the implementation of what is not, because that was when the string is Empty Empty, or can be said that the length is zero string 

  When a variable was designated a value, it will cease to be a Empty, it will be other sub-types, according to the types of data vary, of course, you can still use this keyword Empty these variables change to Empty - type 

  VarTest = Empty 

  There are two ways you can judge whether a variable Empty 

  If varTest = Empty Then 
  Response.Write "The variable is empty." 
  End If 

  Or 

  If IsEmpty (varTest) Then 
  Response.Write "The variable is empty." 
  End If 

Null

  Null information of this type and Empty very similar, but the difference is Empty behalf of a variable has not been initialized, that is, has not been given any value, and a variable for you Null only after its designation as Null.    The most commonly encountered Null opportunities should be in dealing with the database, when a column no information is Null 

  Null designation and the judge very similar methods and Empty 

  VarTest = Null 

  However, you can only use IsNull () function to determine Null, it is because Null is not represented by legal information, you can try the following examples 

  Dim varTest 
  VarTest = Null 
  If varTest = Null Then 
  Response.Write "The variable has a Null value." 
  End If 

  Implementation of the results will not show The variable has a Null value. A variable to determine whether you should use Null IsNull () function 

  Dim varTest 
  VarTest = Null 
  If IsNull (varTest) Then 
  Response.Write "The variable has a Null value." 
  End If 

  When you deal with the database in the Null removed the information, you have to be pretty attention because Null is not represented by legal information, when some function in dealing with math, Null may create some trouble, For example, 

  Dim varTest 
  VarTest = Null 
  VarTest = CLng (varTest) 

  You will see the results "Invalid Use of Null" error message, then look at the following example 

  Dim varTest 
  Dim lngTest 
  VarTest = Null 
  LngTest = 2 + varTest 
  Response.Write TypeName (lngTest) 

  You will find that, with two or Null Null Therefore, when you get the information from the database, you should first use IsNull () to determine whether the column Null, anything properly dealt with, for example, 

  LngQty = oRs ( "Quantuty") 
  If IsNull (lngQty) Then 
  LngQty = 0 
  End If 

  Hope this article will help you! 

Bookmark it: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Google
  • DotNetKicks
  • DZone
  • Furl
  • Netvouz

Tags:

Releated Articles


0 Comments to “How to deal with the database Null (z)”

No Comments. Send your comment.

Leave a Reply

You must be logged in to post a comment.