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

来源:互联网 发布:下载视频软件 知乎 编辑:程序博客网 时间:2024/06/08 20:00
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>

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

<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击