Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 883
  • Last Modified:

If Then Else Syntax Question

I can't seem to get the syntax right.  I am populating from a DB recordset.  What I'd like to achieve is if either the individual recordset column is blank or the recordset itself is "broken" or "missing" then in its place would be: "No Record" rather than the page throwing an error.  Here's what I've been playing with:

<%
Dim rsHeat
Dim rsHeat_cmd
Dim rsHeat_numRows

Set rsHeat_cmd = Server.CreateObject ("ADODB.Command")
rsHeat_cmd.ActiveConnection = MM_heat_STRING
rsHeat_cmd.CommandText = "SELECT * FROM display"
rsHeat_cmd.Prepared = true

Set rsHeat = rsHeat_cmd.Execute
rsHeat_numRows = 0
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>

<% If (rsHeat.Fields.Item("Heat").Value) = "" Then
     If (rsHeat_total = 0) Then %>
         No Record
         <% Else  %>
<%=(rsHeat.Fields.Item("Heat").Value)%>
  <% End If  
End If%>

</body>
</html>
<%
rsHeat.Close()
Set rsHeat = Nothing
%>
0
TCCIRM
Asked:
TCCIRM
  • 2
2 Solutions
 
b0lsc0ttCommented:
TCCIRM,

It looks like you are using vbscript and ASP.  The parenthesis are not needed around the condition in the If statement.  Also, why are you doing the second If statement?  Do you want it to use OR?  The code below may work better for you.  I will assume that you want No Record to print if the value is blank or the total is 0.

<% If rsHeat.Fields.Item("Heat").Value = "" OR rsHeat_total = 0 Then
%>
         No Record
         <% Else  %>
<%= rsHeat.Fields.Item("Heat").Value%>
  <% End If  
End If%>

Let me know if you have any questions.

b0lsc0tt
0
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
You've probably got a null in the value - null doesn't equal ""

You check for a null like this:

If IsNull(rsHeat.Fields.Item("Heat").Value) = True Then
0
 
TCCIRMAuthor Commented:
Using a combination of both:

<% If IsNull(rsHeat.Fields.Item("Heat").Value) = True OR rsHeat_total = 0 Then %>
         No Record
         <% Else  %>
<%= rsHeat.Fields.Item("Heat").Value%>
<%  
End If%>

However........ when the DB record not "null" and the recordset is not "0" then it should populate from whatever is in the "Heat" field.  It does not.  It writes "No Record" to the page.  
0
 
TCCIRMAuthor Commented:
I think my "recordset total" statement is wrong.  If I break the recordset I get an error.  Let me play some more.  Thanks.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now