Question

Checking if DB field is empty

Asked by: mazgwembe

I have an asp page that displays info from an access DB. One of the fields in the database (rationale column) contains some text. I'm having trouble figuring out how to check if the rationale field (rsProposals.fields.item("Rationale").value) contains any thing - i.e. if it's empty/null. When I use:

<td><div align="center"><font size="-1" face="Arial, Helvetica, sans-serif">
<% Response.Write (rsProposals.Fields.Item("Rationale").Value) %></font></div></td>

the rationale text/value shows up fine in my asp page.

The problem comes in when I try to check whether the rationale field contains anything, in order to change the color of the value displayed from the proposal column. This is how I do it:

<td><font size="-1" face="Arial, Helvetica, sans-serif">
      <%
      if isNull(rsProposals.fields.item("Rationale").value) then
         Response.Write "<font color=""#009A76""> "& (rsProposals.Fields.Item("Proposal").Value) &" </font>"
      else
         Response.Write "<font color=""#FF0000""> "& (rsProposals.Fields.Item("Proposal").Value) &" </font>"
       end if
      %>
</font></td>

(All code examples are in a repeat region)

What happens when I do this checking is that the value of the rationale field does not get displayed now. In the HTML table on the asp page, the proposal field comes before the rationale field - if this makes any difference.

Is there any reason why the rationale text/value would fail to show up if I used ISNULL to check it's value when displaying the contents of the proposal field. Same thing happens when I use ISEMPTY. Is there a way around this - or another way to check if a field is empty? Thanks!
      

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-06-10 at 12:11:16ID20643511
Topic

Active Server Pages (ASP)

Participating Experts
5
Points
50
Comments
16

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. helvetica font PLEASE
    I've tried to find Helvetica Font Face everywhere..........any help??? THANKS! mickeymouser
  2. Helvetica
    I need to install Helvetica onto my PC. Where do I find it to download. Not talking about Helv-Condensed.
  3. Helvetica Font
    Where can I get the Helvetica Font for use in MS Word 97?
  4. Arial font and CSS
    For some reason i can't get my CSS design to display the arial font. The CSS is set: font-family:Arial, Helvetica, sans-serif; Yet the font isn't arial. I have also tried font-family:Arial; How can i force it to display Arial?
  5. Helvetica fonts needed
    Where can I find free helvetica fonts.

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: DxpertPosted on 2003-06-10 at 12:18:59ID: 8693705

Actually, you should add the field value to a Variable since you are going to be using it multiple times:

strRaionale = Trim(rsProposals("Rationale"))

Then you can do IsNull(strRaionale) - this will check for NULL values, also (strRaionale = "") - this will check for an empty string, also len(strRaionale) = 0 - this will check that the length is equal to Zero.


<%
strRaionale = Trim(rsProposals("Rationale"))
%>

<td><font size="-1" face="Arial, Helvetica, sans-serif">
     <%
    if  not isNull(strRaionale ) and  strRaionale <> "" then
       Response.Write "<font color=""#009A76""> "& (rsProposals.Fields.Item("Proposal").Value) &" </font>"
     else
       Response.Write "<font color=""#FF0000"">SOME OTHER VALUE</font>"
      end if
    %>
</font></td>


=:o))

 

by: Bill_HardingPosted on 2003-06-10 at 12:21:22ID: 8693725

instead of checking for nothing, check for something.

if len(rsProposals.Fields.Item("Proposal").Value) > 1 then ...
else....
end if

But, no text means no color at all, why change color when there is no text?

 

by: DxpertPosted on 2003-06-10 at 12:21:35ID: 8693727

Sorry, i didn't see the other field "Proposal".

What is it exactly that you want to do?
- Print "Proposal" whenever "Rationale" is not null or empty?

 

by: mazgwembePosted on 2003-06-10 at 12:40:52ID: 8693881

For now, I want to print out the value of proposal in a different color if the value of rationale is empty/null - or not. I eventually want to have the value of proposal displayed in form of a link which when clicked on would open a new window containing the value of rationale - i.e. if there's something in rationale, there's a link, - if there's nothing, no link...

 

by: DxpertPosted on 2003-06-10 at 12:43:24ID: 8693894

did my sample work?

 

by: DxpertPosted on 2003-06-10 at 12:47:40ID: 8693920

You could also do something like this:


<%
strRaionale = Trim(rsProposals("Rationale"))
strProposal = Trim(rsProposals("Proposal"))

if  not isNull(strRaionale ) and  strRaionale <> "" then
   strFontColor = "#009A76"
else
   strFontColor = "#FF0000"
end if
%>
<td>
     <font size="-1" face="Arial, Helvetica, sans-serif">
            <font color="<%=strFontColor%>"><%=strProposal %></font>
     </font>
</td>




=:o))

 

by: mazgwembePosted on 2003-06-10 at 13:22:55ID: 8694188

Bill_Harding:

I tried your approach as
 
       if len(rsProposals.Fields.Item("Rationale").Value) > 1 then
       Response.Write "<font color=""#009A76""> "& (rsProposals.Fields.Item("Proposal").Value) &" </font>"
       else
       Response.Write "<font color=""#FF0000""> "& (rsProposals.Fields.Item("Proposal").Value) &" </font>"
       end if

This changes the color of the value of proposal according to whether the Rationale field contains something,as desired, but the value for Rationale doesn't show up!...

When I take out the [if len(rsProposals.Fields.Item("Rationale").Value) > 1 then]  logic  and leave just:

Response.Write "<font color=""#009A76""> "& (rsProposals.Fields.Item("Proposal").Value) &" </font>"

The value of Rationale shows up now. Here's what Rationale's ASP code looks like:

<td><div align="center"><font size="-1" face="Arial, Helvetica, sans-serif">
      <%
      Response.Write (rsProposals.Fields.Item("Rationale").Value) %></font></div></td>




Dxpert:

I tried your example, as outlined below:

              <%
      dim strRationale
      strRationale = Trim(rsProposals("Rationale"))
       if  not isNull(strRationale ) and  strRationale <> "" then
       Response.Write "<font color=""#009A76""> "& (rsProposals.Fields.Item("Proposal").Value) &" </font>"
      else
       Response.Write "<font color=""#FF0000""> "& (rsProposals.Fields.Item("Proposal").Value) &" </font>"
       end if
      %>

'strRationale = Trim((rsProposals.Fields.Item("Rationale").Value)) also seems to work.

Result: - the value/txt of proposal shows up in different colors depending on whether the value for Rationale is empty/null - GOOD, but then again the value of Rationale REFUSES to show up! Here's the code for Rationale's display:

<td><div align="center"><font size="-1" face="Arial, Helvetica, sans-serif">
      <% Response.Write (rsProposals.Fields.Item("Rationale").Value)%>
</font></div></td>

Do you guys know why the value for Rationale doesn't show up when we include logic to check whether or not it's empty - it seems to be doing this across the board regardless of whether we use Len, ISNULL or ISEMPTY!

 

by: mazgwembePosted on 2003-06-10 at 13:31:16ID: 8694260

I tried:                
                <%
      dim strRationale
      strRationale = Trim(rsProposals("Rationale"))
       Response.Write "<font color=""#FF0000""> "& (rsProposals.Fields.Item("Proposal").Value) &" </font>"
      %>

and the value of Rationale still wouldn't show up - it is only when I commented out 'strRationale = Trim(rsProposals("Rationale")) that the value for Rationale DID show up...

I'm not sure what's going on here, and why the value for Rationale is absent with the inclusion of something as benign as
strRationale = Trim(rsProposals("Rationale"))!

 

by: DxpertPosted on 2003-06-10 at 13:41:13ID: 8694339

Ok can you just post you whole code and point where you are getting the error? It's getting very hard to understand these pieces...

=:o))

 

by: mazgwembePosted on 2003-06-10 at 14:02:38ID: 8694510

Ok, I'll try this again... Like I said I have an access DB whole values I'm pulling up and displaying on main.asp. Two of the columns in the DB are the Proposals and Rationale columns. For now I'm trying to change the color of the value of PROPOSAL for each row in the repeat region, depending in whether the value of RATIONALE is null/empty - or not.

The way this info is being displayed on main.asp is on an HTML table with columns corresponding to the columns in the access DB. The code I've been providing, above, is that of the Proposal and Rationale columns. That said, I'm having problems with the value of the Rationale column not showing up when I try to use some logic to determine whether the value of Rationale is empty.

The code b4 using the logic looks like:

For Proposal column:
<td><font size="-1" face="Arial, Helvetica, sans-serif">
               <%
      dim strRationale
       Response.Write "<font color=""#FF0000""> "& (rsProposals.Fields.Item("Proposal").Value) &" </font>"
      %>
</font></td>

For Rationale column:
 <td><div align="center"><font size="-1" face="Arial, Helvetica, sans-serif">
      <%
      Response.Write (rsProposals.Fields.Item("Rationale").Value)
      %>
</font></div></td>

In this setup, the value of the Rationale column shows up in main.asp


The code using the logic to check whether the Rationale column is empty/null looks like:

For Proposal column:
<td><font size="-1" face="Arial, Helvetica, sans-serif">
      dim strRationale
      strRationale = Trim(rsProposals("Rationale"))
      'strRationale = Trim((rsProposals.Fields.Item("Rationale").Value))
      if  not isNull(strRationale ) and  strRationale <> "" then
         Response.Write "<font color=""#009A76""> "& (rsProposals.Fields.Item("Proposal").Value) &" </font>"
      else
         Response.Write "<font color=""#FF0000""> "& (rsProposals.Fields.Item("Proposal").Value) &" </font>"
       end if
      %>
 </font></td>


For Rationale column:
 <td><div align="center"><font size="-1" face="Arial, Helvetica, sans-serif">
      <%
      Response.Write (rsProposals.Fields.Item("Rationale").Value)
      %>
</font></div></td>

With the logic in, the value for the Rationale column fails to get displayed - is blank, which is where I'm stuck/don't understand...

Have I explained myself better/Does it make sense now?  Thanks again for your suggestions

 

by: abhishek178Posted on 2003-06-10 at 22:24:56ID: 8696716

Have u tried this way may be it will work

strRaionale = Trim(rsProposals("Rationale"))


if (Isempty(strRaionale)) then
---------------------
else
---------------------
end if

 

by: estheraPosted on 2003-06-11 at 00:33:56ID: 8697311

What datatype is rational
If it is a text fielde then try

if rsProposals("Rationale")="" then

'this means it is blank

if it is a true false then
if rsProposals("Rationale")=false then

if it is a number
then
if rsProposals("Rationale")=0 then

 

by: mazgwembePosted on 2003-06-11 at 07:46:38ID: 8700263

Ok, I've changed my approach a bit - made things simpler. What I'm doing now is I'm trying to display the value of Rationale for a given row result in form of a link that's independent of whether or not the Rationale field is empty. I'm using the value of the company field as the link text. Here's the code:

main.asp
<td><div align="center"><font size="-1" face="Arial, Helvetica, sans-serif">
    <%
    dim str_rationale
               str_rationale = rsProposals("Rationale")      
     response.write "<A href = 'rationales2.asp?str_text=" & str_rationale & " ' target = '_blank'>"
     Response.Write (rsProposals.Fields.Item("Company").Value)
     Response.Write "</A>"
     %>
</font></div></td>


rationales2.asp

dim passed_text
passed_text = request.querystring("str_text")

if len(str_text) = 0 then
response.write " dang it, it still didn't work.."
else
response.write "The value passed from the previous link = " & str_text & "<BR>"
end if

What happens now is that the value of Rationale can be seen (on the browser status bar) when I hover over the link to it, but when I click on the link itself to view the full Rationale text in the new window (as per the code) there's nothing in "str_text" - I get "dang it, it still didn't work.." It's quite baffling! - see anything I'm doing wrong in passing/retrieving the variables? Thanks guys.

 

by: mazgwembePosted on 2003-06-11 at 13:59:09ID: 8703281

ANYONE?

 

by: CorrupticusPosted on 2003-06-23 at 09:41:37ID: 8782801

I would take the approach of passing the record's ID from main.asp to the rationales2.asp,  pulling the value of the ID out of the querystring, and then doing a database call on the second page using the value of ID in your WHERE clause.  

 

by: mazgwembePosted on 2003-06-23 at 09:42:49ID: 8782810

that worked incredibly well, Corrupticus - Thanks, the pts r urs!

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...