经典ASP脚本不返回ELSE中的值

经典ASP脚本不返回ELSE中的值

问题描述:

第一次海报和ASP编程相当新。经典ASP脚本不返回ELSE中的值

我想添加一个功能,检查一个字段是否为空,如果是的话返回一个设定值。 这是我迄今为止得到:

'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 
%> 

现在的问题:当存在备份数据库值时,它表明它背后的价值与合并“(备份)”。所以这工作正常。问题是,当没有找到值时,它不会返回任何值。

我曾尝试做一些谷歌搜索,但也许我在这里忽略了一些东西。 任何想法它可能是什么?

由于提前,

埃里克

+0

查询中有多少条记录回来?我的猜测是,没有记录,你的代码说在这种情况下不做任何事情。 –

Response.Write语句包含在If Not rsBackup.EOF Then声明。

如果rsBackup中没有记录,则不会写入任何内容。

+0

感谢您的快速响应。我把第一个END IF移到了ELSE之前,现在它完美地工作了。感谢一百万的洞察力。 – Meridius