Tuesday, November 22, 2005

VB.NET: Stupid ands!

this statement will fail if the column is dbnull

if not reader.item("age") is dbnull.value and reader.item("age") <>

It fails because vb for some reason evaluates all conditions in the statement and then determines wether it is true or false. To get around this use andalso

if not reader.item("age") is dbnull.value andAlso reader.item("age") <>

this will evaluate the first condition and if the first condition is true it will evaluate the second one. This can also be usefull when the second statement is process intensive.


Post a Comment

<< Home