Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2007
    Posts
    7

    Unanswered: empty value of ms access, asp, vbscript

    How we can recognize an empty value of ms access field.


    suppose :

    Code:
    Dim empVal, empVal1, num
    
    num = 0
    
    empVal = Recordset.Fields.Item("subj").Value
    
    empVal1  = Recordset.Fields.Item("org").Value
    here empVal = "" and empVal1 = "" i. e. in the database there are no value i.e. empty

    so if i wrote

    Code:
    If ( (empVal = "") AND (empVal = "") ) Then
    
     num = num + 1 
    
     response.write num
     response num
    
    end if
    here value should show "1"

    But it is not entering within the if condition.

    So, how can we evaluate the value of empty

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Try testing for a NULL value as well as an empty string.
    George
    Home | Blog

  3. #3
    Join Date
    Jul 2003
    Location
    Amsterdam, Nederland
    Posts
    450

    Smile re

    what i normaly do if i know when a value can be null
    is

    Dim empVal, empVal1, num
    num = 0
    empVal = Recordset.Fields.Item("subj").Value & ""
    empVal1 = Recordset.Fields.Item("org").Value & ""

    so you allways have a empty string value

  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    That logic is dangerous in general. You can get away with it in certain languages, but you'll find yourself scratching your head when rs("field1") & "" comes back null as you move ahead. It's also confusing to programmers who come in behind you and have to decide what your intent was by concatenating a zero length string to a random field.

    But then, I'm nitpicky like that.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  5. #5
    Join Date
    Jul 2003
    Location
    Amsterdam, Nederland
    Posts
    450

    Re.RE

    Quote Originally Posted by Teddy
    That logic is dangerous in general. You can get away with it in certain languages, but you'll find yourself scratching your head when rs("field1") & "" comes back null as you move ahead. It's also confusing to programmers who come in behind you and have to decide what your intent was by concatenating a zero length string to a random field.

    But then, I'm nitpicky like that.
    True , True
    Normaly i would use
    String.IsNullOrEmpty(y) in .Net
    or in VB IsEmpty(x) / IsNothing or IsNULL depending what i was expecting

    but in his example he's allready assigning it to a non specified value
    ' Dim empVal, empVal1, num
    without perceding check (so i thought what the heck)
    and afterwords he's checking on an empty string
    ' If ( (empVal = "") AND....

    if this is his check, my previus example will work
    And if you ask out recordset("Name") & ""
    and the rs is Null it will return "" in VB
    if rs isn't nothing
    don't know if it will do the same in C++

Posting Permissions

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