www.webdeveloper.com
Results 1 to 8 of 8

Thread: Checking for Empty Record (should be simple!)

  1. #1
    Join Date
    Jan 2005
    Posts
    42

    Checking for Empty Record (should be simple!)

    I am looping through a recordset of products and want to set a flag to true if any of them do not have a postage:

    Code:
    postageFee = rs("postageFee")
    
    If postageFee = "" Then
    	postageMissing = True
    End If
    This doesn't work, records with no postage do not enter the If statement. How do I test for an empty record?

    Any Ideas?

  2. #2
    Join Date
    Dec 2005
    Posts
    155
    hi

    if the datatype of postage fee is currency or number the code won't work (default value may be 0)

    if it is text try this

    Code:
    If Trim(postageFee) = "" Then
        postageMissing = True
    End If
    Last edited by jvanamali; 12-17-2005 at 05:26 AM.

  3. #3
    Join Date
    Jan 2005
    Posts
    42
    The datatype is a float (mySQL), it doesn't default to zero - when i print the empty record it looks like an empty string.

    I can get it to work like this - strange! Would like a more sensible solution though.

    Code:
    If postageFee <> "" Then
    	' do nothing
    Else
    	postageMissing = True		
    End If

  4. #4
    Ubik's Avatar
    Ubik is offline &lt;%= &quot;New Meja Hor&quot; %&gt;
    Join Date
    Nov 2005
    Location
    Earth
    Posts
    361
    I use:

    PHP Code:
    If Trim(postageFee&" ") = "" Then
        postageMissing 
    True
    End 
    If 
    for some reason, this seemes to work better to add a space to the trim function in some cases. Maybe someone who knows more asp than I can explain it.

  5. #5
    Join Date
    Jan 2005
    Posts
    42
    Cheers that's a bit neater, still a bit of a strange method though!

    Must be something weird with ADO.

  6. #6
    Join Date
    Jun 2004
    Location
    Kansas City, MO
    Posts
    1,607
    axys, does Ubik method work if you remove the & " " from the Trim Statement.

    Trim should take care of both left and right empty spaces.

    I would also check the database as the field returns nothing but somehow a space was entered into the field. Thus causing the problem that you currently have.

  7. #7
    Join Date
    Dec 2003
    Location
    England, UK
    Posts
    432
    i would do it like this

    Code:
    postageFee = rs("postage") & ""
    
    If postageFee = "" Then
    	postageMissing = True
    End If
    or this

    Code:
    If rs("postage") & "" = "" Then
    	postageMissing = True
    End If
    its just a case of where you do the conversion to a string. if you don't do it then you are comparing some kind of ADO object with an empty string, which will always be false.

    i'm not sure that using trim has any effect in this situation either, as you are retrieving a numeric field and not a character string, and therefore there will never be anything to take off either end.

  8. #8
    Ubik's Avatar
    Ubik is offline &lt;%= &quot;New Meja Hor&quot; %&gt;
    Join Date
    Nov 2005
    Location
    Earth
    Posts
    361
    I was using trim to get rid of the extra space I inserted to the string, this was before I saw anyone else use the [rs("postage") & "" = ""] method.

    Both methods should have the same result(s) though, as both method instantiate the variable, convert it to a sting and compare it to a null string, making the if statement TRUE if NULL.

    asp has an ISNULL(variable) function, but that doesn't always work, depending on the type of variable, and the value of the variable.
    Last edited by Ubik; 12-19-2005 at 12:01 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles