Link to home
Start Free TrialLog in
Avatar of adm-computing
adm-computing

asked on

Testing for a recordsets value being equal to nothing in ASP

Can someone tell me the best way of testing for a recordset's field's value being equal to 'nothing' (or null?) in ASP?

For example, I have an If statement that needs to test if a field's value is set to nothing. I would have thought it could be done the following way but it appears it cannot:

<% if (recordset.Fields.Item("myfield").Value) = ""  then %>
Avatar of Dirar Abu Kteish
Dirar Abu Kteish
Flag of Palestine, State of image

U have to check before if the record set returned result. if not recordset.EOF

-dirar
Avatar of adm-computing
adm-computing

ASKER

I think you misunderstood my question - Im not checking if the recordset is empty, just if one of its fields is empty.
ASKER CERTIFIED SOLUTION
Avatar of Dirar Abu Kteish
Dirar Abu Kteish
Flag of Palestine, State of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i use a function to return me a boolean value...

Function reqField(strFormField)
      reqField = True 'by default
      if strFormField = "" then reqField = False
      if isnull(strFormField) then reqField = False
      if len(strFormField) <= 0 then reqField = False
      if isempty(strFormField) then reqField = False
End Function



simple do a:
<%if not reqField(recordset.Fields.Item("myfield").Value) then%>
I didn't repost what dxz had already provided, in order to not duplicate answers as you have done ;)

And, of course, I would never post an answer like using len() for null values <=0, as you have done here: if len(strFormField) <= 0 then reqField = False (that would never work properly).  Give it a try.

 <%
i=null 'simulate null from database

response.Write "len:" & len(i)
if len(i) <= 0 then
  response.Write "test"
end if
%>
Come on, at least accept when you're wrong.  The code you have won't work properly.  I don't have a problem with you.  I just have a problem with people posting the same answers, and also not testing code they post.  That's all.  Otherwise, I wouldn't bring it up.  Test your code man.  We're supposed to be teaching, let's not teach them the wrong ways to code.
This is becoming strange. If you want to fight, fight somewhere else. The author of this question is looking for an answer and shouldn't read all this nonsense.
Anyway, I think adm-computing should have solved the problem by now, so let's hear what he is going to say ;)

-dirar
my code works perfectly.  Have a look again and test it out for your self.

And yes, you do apparently have a problem with, as every single question I post in you have something to say against something I've posted.

Request has been made in support to do something about you...good luck




for a breakdown of the function:
Function reqField(strFormField)
      reqField = True 'by default
      if strFormField = "" then reqField = False 'checks for "" if it is, set reqField to false
      if isnull(strFormField) then reqField = False 'checks for isnull if it is, set reqField to false
      if len(strFormField) <= 0 then reqField = False 'checks for lenght less than or equalto 0 if it is, set reqField to false
      if isempty(strFormField) then reqField = False 'checks for isempty if it is, set reqField to false
End Function
Ive been away from my computer for a couple of hours and clearly missed all the excitement!

Will test all suggested solutions tomorrow morning and award points to the best solution (and least childish poster!)
adm-computing - thanks, and please be sure to read all the information carefully, amidst the banter.