我正在使用 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
谢谢!