首页 > 开发 > Asp > 正文

ASP自定义函数,仿VBA中域函数DLookup

2020-02-03 16:40:08
字体:
来源:转载
供稿:网友
function dlookup(strfieldname, strtablename, strwhere, objconn)
'参考access vba 中的dlookup函数
'由于环境不同,加了objconn参数,直接将adodb.connection直接调进来
dim strsql
dim rs
set rs = server.createobject("adodb.recordset")
'下面要调用外部的一个自定义函数 checksql()
strfieldname = checksql(strfieldname)
if strwhere <> "" then
strwhere = " where " & strwhere
end if
strsql="select "&strfieldname&" from "&strtablename&" " & strwhere
'debugstop strsql
on error resume next
rs.open strsql, objconn, 1, 1
if err <> 0 then
response.write err.description
response.end()
end if

if rs.eof and rs.bof then
dlookup = ""
else
'要调用一个自定义函数 nz
'详细内容请参考 access vba 帮助中的资料
dlookup = nz(rs(strfieldname), "")
end if
rs.close
end function

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表