locked
Check if query result is empty RRS feed

  • Question

  • User389116203 posted
    Hello,

    First time poster and new to ASP programming.
    I have a functional database to where i am trying to add new functionality.

    I'm trying to add the idea to check if a returned string is empty, if so get value from a backup table which 
    holds historical information. I've tried a lot of different things now and a full day of google didn't help 
    me figure it out.

    Here is what i have got for the specific part:

    EngineSDB.asp
    set dbGlobalWeb=Server.CreateObject("ADODB.Connection")
    dbGlobalWeb.Provider="Microsoft.Jet.OLEDB.4.0"
    dbGlobalWeb.Open dbadres
    SqlJunk = "SELECT * FROM CMDBtable"
    ~~some search options with WHERE statements~~
    Set rsGlobalWeb = Server.CreateObject("ADODB.Recordset")
    rsGlobalWeb.Open SqlJunk, dbGlobalWeb, 3
    
    Searchresults.asp
    <%  If rsGlobalWeb("Serial") <> "" Then
    		response.write("<td>" & rsGlobalWeb("Serial") & "</td>")
    	Else
    		SqlBackup = "SELECT * FROM CMDBbackup WHERE Naam_Cattools = '" & rsGlobalWeb("SNMP_Custom_2") & "'" 
    		Set rsBackup = Server.CreateObject("ADODB.Recordset")
    		rsBackup.Open SqlBackup, dbGlobalWeb, 3
    		If rsBackup("Serial") <> "" Then
    			response.write("<td>" & rsBackup("Serial") & " (backup)</td>")
    		else
    			response.write("<td>No historical data found</td>")
    		End if
    	End if
    %>	
    The problem is: once it comes across missing information it stops there instead of 
    showing the "No historical data".
    Error message i get is: error '80020009' /i-base/Searchresults.asp, line 47... 
    line with: If rsBackup("Serial") <> "" Then

    Is there something i missed due to inexperience or any idea's what it could be?

    Thanks in advance
    Erik
    Monday, October 10, 2011 8:53 AM

Answers

  • User-952121411 posted

    Hello -

    This is an ASP.NET forums site which is different from Classic 'ASP' programming and is not supported in this forum. Try the following forum which will help you:

    ASP VB Forums:

    http://www.vbforums.com/forumdisplay.php?s=a83149a82376e2021f2e68075ace0fb0&f=4

    With this I will say you might want to check if the Recordset has any value 1st before accessing its fields, and then making sure a field is not null too:

    'Check to see if any records exist:
    If Not rsBackup.EOF Then
       If Not IsNull(rsBackup("Serial")) And (rsBackup("Serial") <> "") Then
       Else
       End If
    End If
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 10, 2011 3:36 PM

All replies

  • User-952121411 posted

    Hello -

    This is an ASP.NET forums site which is different from Classic 'ASP' programming and is not supported in this forum. Try the following forum which will help you:

    ASP VB Forums:

    http://www.vbforums.com/forumdisplay.php?s=a83149a82376e2021f2e68075ace0fb0&f=4

    With this I will say you might want to check if the Recordset has any value 1st before accessing its fields, and then making sure a field is not null too:

    'Check to see if any records exist:
    If Not rsBackup.EOF Then
       If Not IsNull(rsBackup("Serial")) And (rsBackup("Serial") <> "") Then
       Else
       End If
    End If
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 10, 2011 3:36 PM
  • User389116203 posted

    Hello,

    Thanks for the reply. I'll post it on that forum the next time i have an issue.

    For this time you solved my problem! Thanks a million.

    I just pasted in the code, added the response.write and it works!

    Erik

    Tuesday, October 11, 2011 3:02 AM