1

First time poster and fairly new to ASP programming.

I am trying to add a functionality that checks if a field is empty, if so return a set value. Here is what i have got so far:

'rsGlobalWeb is basicly declared the same as rsBackup just in a different asp file with also the db connection.
<%  If rsGlobalWeb("Serial") <> "" Then
        response.write("<td>" & rsGlobalWeb("Serial") & "</td>")
    Else
        SqlBackup = "SELECT * FROM CMDBbackup WHERE Naam_Cattools = '" &     rsGlobalWeb("Device_name") & "'" 
        Set rsBackup = Server.CreateObject("ADODB.Recordset")
        rsBackup.Open SqlBackup, dbGlobalWeb, 3
        If Not rsBackup.EOF Then
            If Not IsNull(rsBackup("Serial")) And (rsBackup("Serial") <> "")     Then     
                response.write("<td>" & rsBackup("Serial") & " (backup)</td>")
            Else
                response.write("<td>No historical data found</td>")
            End if
        End if
    End if
%>

Now for the problem: when there is a value in the backup database it shows that value combined with the "(backup)" behind it. So that is working fine. The problem is that when there is no value found, it does not return anything.

I have tried do to some google searches but perhaps i am overlooking something here. Any thoughts what it could be?

Thanks in advance,

Erik

1
  • How many records come back in your query? My guess is that there's no records and you code says not to do anything in that case. Commented Oct 11, 2011 at 9:51

1 Answer 1

1

Your Response.Write statements are enclosed in an If Not rsBackup.EOF Then statement.

Nothing will be written if there are no records in rsBackup.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the quick response. I moved the first END IF to before the ELSE and now it works perfectly. Thanks a million for the insight.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.