代码之家  ›  专栏  ›  技术社区  ›  sholsinger

利用ADO.NET在经典ASP脚本中

  •  2
  • sholsinger  · 技术社区  · 14 年前

    如果我确实需要重新实现这个特性,那么最好的方法是什么?

    set cmd = Server.CreateObject("ADODB.Command")
    cmd.ActiveConnection = conn
    cmd.CommandText = "SELECT COUNT(*) FROM corp_crcchallenge WHERE cc_email = ?"
    appendParam cmd, "email", adVarChar, adParamInput, 255, email
    emailFound = cmd.ExecuteScalar()
    

    appendParam是我用来附加param的子例程,这样我就不用在这个应用程序的另一部分重复太多了。它使它更容易阅读。

    我在想,如果我需要重新实现的话,下面这样的东西可能是正确的方向。(还是VBScript)

    emailFound = cmd.Execute(Nothing, Nothing, adExecuteRecord)
    
    1 回复  |  直到 14 年前
        1
  •  2
  •   bugtussle    14 年前

    快速示例:

    set cmd = Server.CreateObject("ADODB.Command")
    set rs = server.createObject("ADODB.RecordSet")
    
    with cmd
     .ActiveConnection = conn
     .CommandText = "SELECT COUNT(*) as MyCount FROM corp_crcchallenge WHERE cc_email = @p1"
     .createparameter("@p1",adVArChar,adParamInput,,email)
     set rs = .Execute
    end with
    
    rtn = rs.fields("MyCount")
    

    n = MyScalar("SELECT COUNT(*) FROM corp_crcchallenge WHERE cc_email = @p1","abc@def.com")
    
    function MyScalar(sql, Param1)
        set cmd = Server.CreateObject("ADODB.Command")
        set rs = server.createObject("ADODB.RecordSet")
    
        with cmd
            .ActiveConnection = conn
            .CommandText = sql
            .createparameter("@p1",adVArChar,adParamInput,,Param1)
            set rs = .Execute
        end with
    
        MyScalar = rs.fields(0)
    
    end function