?
Solved

Testing for a recordsets value being equal to nothing in ASP

Posted on 2007-07-31
12
Medium Priority
?
748 Views
Last Modified: 2012-06-21
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 %>
0
Comment
Question by:adm-computing
  • 4
  • 3
  • 2
  • +1
11 Comments
 
LVL 6

Expert Comment

by:Dirar Abu Kteish
ID: 19599302
U have to check before if the record set returned result. if not recordset.EOF

-dirar
0
 

Author Comment

by:adm-computing
ID: 19599414
I think you misunderstood my question - Im not checking if the recordset is empty, just if one of its fields is empty.
0
 
LVL 6

Accepted Solution

by:
Dirar Abu Kteish earned 1000 total points
ID: 19599663
check this:

if (IsEmpty(recordset.Fields.Item("myfield").Value))

-dirar
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Assisted Solution

by:golfDoctor
golfDoctor earned 1000 total points
ID: 19599987
Put empty space on end:

<% if (recordset("myfield")&"") = ""  then %>

OR, check for null:

<% if  isnull(recordset("myfield"))  then %>

OR, check the length:

<% if len(recordset("myfield")&"") = 0  then %>
0
 
LVL 25

Expert Comment

by:kevp75
ID: 19600067
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%>
0
 
LVL 16

Expert Comment

by:golfDoctor
ID: 19600981
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
%>
0
 
LVL 16

Expert Comment

by:golfDoctor
ID: 19601426
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.
0
 
LVL 6

Expert Comment

by:Dirar Abu Kteish
ID: 19601496
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
0
 
LVL 25

Expert Comment

by:kevp75
ID: 19601554
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
0
 

Author Comment

by:adm-computing
ID: 19602002
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!)
0
 
LVL 16

Expert Comment

by:golfDoctor
ID: 19602042
adm-computing - thanks, and please be sure to read all the information carefully, amidst the banter.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question