Nulls & Integers

Results 1 to 2 of 2

Thread: Nulls & Integers

  1. #1
    Join Date
    Dec 1969

    Default Nulls & Integers

    Apologies if this has been discussed before but have not been unable to work out the best approach.<BR><BR>In my database, I have many integer fields but if it that field is not applicable/defined on a certain row then it is just a Null in the database.<BR><BR>When I read this into a variable in VB.Net on an ASP.Net page the obvious choice to use is an Integer value but this is not ideal as it cannot take Null values and the Nothing value is 0 which often has a "proper" meaning to me other than merely unspecified.<BR><BR>A possible way round this is to use an Object data type. This is essentially what did with classic ASP as of course VBScript is typeless.<BR><BR>I note covers this topic with improvements made for the 2005 release but can&#039;t really use a beta product at this moment.<BR><BR>Any thoughts welcomed.<BR><BR>Cheers<BR>Tim Grose

  2. #2
    Join Date
    Dec 1969

    Default two things to do

    1) in your SQL, protect yourself against NULL&#039;s:<BR><BR>Instead of:<BR>SELECT SomeNullableIntField FROM SomeTable<BR><BR>Say:<BR>SELECT IsNull(SomeNullableIntField,1-) As SomeNullableIntField FROM SomeTable<BR><BR><BR>or 2) (and this is what i do in all my stuff and it works great)<BR><BR>Run those columns (or anything else for that matter) through a function that "washes" the value<BR><BR>I have defined in Module (so every page has un-instantiated access to it):<BR><BR>[code language="VB.NET"]Public Function Clng0(ByVal i_Value As Object) As Long<BR> Try<BR> Return Clng(i_Value)<BR> Catch ex As Exception<BR> Return 0<BR> End Try<BR>End Function[/code]<BR><BR>now no matter what gets passed in, a number comes out (in VB.NET, "long" and "integer" seem to be interchangable)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts