HLRosenberger
asked on
Checking for NULL
If believe I've seen this done before, but how do I handle a NULL from a database on this statement:
Reader.Item(Reader.GetOrdi nal("locat ion"))
I know I could first do:
If Not IsDBNull(Reader.Item(Reade r.GetOrdin al("locati on"))) then
but is there a way on the Reader statement to tell it to convert NULL to a space for text and 0 for numeric?
Reader.Item(Reader.GetOrdi
I know I could first do:
If Not IsDBNull(Reader.Item(Reade
but is there a way on the Reader statement to tell it to convert NULL to a space for text and 0 for numeric?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
in your sql query, you can do this:
select field1, field2, isnull(location, 0) as location from tablename
select field1, field2, isnull(location, 0) as location from tablename
You may use:
IIF(IsDBNull(Expression) and (Not Information.IsNumeric(Expr ession)) , " ", IIF(Information.IsNumeric( Expression ) and IsDBNull(Expression), 0 , defaultvalue)
Also, you can use Coalesce() in SQL which returns first Non-null value.
IIF(IsDBNull(Expression) and (Not Information.IsNumeric(Expr
Also, you can use Coalesce() in SQL which returns first Non-null value.
ASKER
Thanks. IsNull works fine for what I want.
Textbox1.Text = IsStringNull(reader.item(1
TextBox2.Text = IsIntNull(reader.item(2))
http://www.codeproject.com/KB/vb/BeginnerExtensionMethods.aspx
http://www.developer.com/net/vb/article.php/3679651/Implementing-Extension-Methods-in-VBNET.htm