gpt4 book ai didi

mysql - 如何在 ASP 中测试空 SQL 结果

转载 作者:行者123 更新时间:2023-11-29 03:15:19 25 4
gpt4 key购买 nike

我正在使用 MySQL 数据库从 ASP 运行查询,我想根据带有人名(全名)的结果创建一个变量 (ssResult),如果记录不存在,我想分配文本 'N/A' 到变量,下面的代码,我目前为我的数据库连接使用函数 getOther,它传递列名“fullname”:

ssResult = getOtherElse("SELECT fullname FROM table WHERE id=" & inArr(j), "fullname")

下面是函数 getOtherElse 的代码,它仅在返回结果时有效,但在结果为空时无效:

Function getOtherElse(inSQL, getColumn)
Dim conn, rstemp
Set conn = Server.CreateObject("ADODB.Connection")
conn.open myDSN
Set Session("lp_conn") = conn
Set rstemp = Server.CreateObject("ADODB.Recordset")
rstemp.Open inSQL, conn
if not rstemp.eof then
rstemp.movefirst
getOtherElse=rstemp.fields(getColumn)
else
getOtherElse="N/A"
end if
rstemp.close
set rstemp=nothing
conn.close
set conn=nothing
End Function

谢谢!

最佳答案

你可以试试换行

if not rstemp.eof then

if rstemp.RecordCount > 0 then

关于mysql - 如何在 ASP 中测试空 SQL 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/317424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com