Results 1 to 6 of 6

Thread: checking if a string is null

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    checking if a string is null

    d is declared as a string and I want to check and see if it's null. IsNull is giving me an error, is there a function in .NET to check if a string is null?

    VB Code:
    1. If UCase(objDR("JOB_REQD_OPT_SP")) = "Y" And (IsNull(d) Or Trim(d) = "") Then

  2. #2
    Addicted Member
    Join Date
    Feb 2002
    Location
    closed
    Posts
    196
    checking whether the string 'is nothing' should do the trick.

    Code:
    dim myNullString as string
    if myNullString is nothing then
        'do something or not
    end if
    Cheers

  3. #3

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    whats the difference between:

    VB Code:
    1. IsNull(mystring)
    2. IsNothing(mystring)
    3. mystring = ""

  4. #4
    Addicted Member
    Join Date
    Feb 2002
    Location
    closed
    Posts
    196
    isNull is a check for variants ( i think!) dunno if vb.net still uses this

    in vb.net strings are taken from the object hirearchy, therefore you can check it's current state by running Is Nothing (not IsNothing) against it.

    the use of nulls is not really part of the VB syntax like in Java or C++ etc.

    mystring = "" is not truly null. It's just a zero length string...
    Last edited by powdir; Mar 31st, 2003 at 10:49 AM.

  5. #5
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Reading, UK
    Posts
    870
    you can use isnull for checking database fields that are returned to a dataset or something to check that they hold a value.
    www.vb-tech.com
    .Net Freelance Development
    http://weblog.vb-tech.com/nick
    My blog

  6. #6
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    You can use System.DBnull object as well .

Posting Permissions

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



Click Here to Expand Forum to Full Width