How to test for an empty SQL result in ASP

给你一囗甜甜゛ 提交于 2019-12-06 09:25:14

You could try changing the line

if not rstemp.eof then

with

if rstemp.RecordCount > 0 then

Replace this block of code:

if not rstemp.eof then
    rstemp.movefirst
    getOtherElse=rstemp.fields(getColumn)
else
    getOtherElse="N/A"
end if

with this block of code:

Dim output
output = "N/A"

If Not rstemp.eof Then
    rstemp.movefirst
    value = rstemp.fields(getColumn)

    If trim(value) = "" Then
        value = "N/A"
    End If
End If

getOtherElse = value

The above code always assumes nothing is being returned, until the connection actually sets it as being returned. And then the the value is checked for an empty string and sets the value also as "N/A"

Why not change the SQL to only pull out a result with a First Name, that way the "N/A" would apply:

sResult = getOtherElse("SELECT fullname FROM table WHERE id=" & inArr(j), "fullname AND fullname<>''")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!