14Aug/090
Checking for null
Checking for null is done differently in each langauge.
* In a string (C#):
if (string.IsNullOrEmpty(myString))
{ }
* In a database (T-SQL):
SELECT * FROM [Customers] WHERE Address IS NULL
* Database return value (C#):
if (myProperty == DBNull.Value)
{ }
* In Javascript:
if (myVariable == null)
{ }
* In Javascript - check if an object exists or has been created yet. This is different than checking for a null value:
if (typeof(jQuery) == 'undefined')
{ }
* In ASP:
if myVariable is null then end if
* In ASP - check if an object exists - example when receiving an XML object:
Set SourceObj = Server.CreateObject("MSXML2.DOMDocument.6.0")
SourceObj.async = false
SourceObj.setProperty "SelectionLanguage", "XPath"
SourceObj.loadXML( xmlhttp.responseText )
uid = SourceObj.documentElement.selectSingleNode("//sessionId")
if uid is nothing then
uid = "n.a."
else
uid = uid.text
end if
* In PHP: