ASP 3.0 Declare ADO Constants w/out Including ADOVBS.inc

前端 未结 3 732
情歌与酒
情歌与酒 2021-01-20 07:29

I\'ve written a simple form handler script using ASP3.0/VBScript and would like to add the inputted data (via the web) to an Access database located on my server. I\'m using

相关标签:
3条回答
  • 2021-01-20 07:47

    you have a couple of options to choose from. You can reference the metadata library in your page ( or in your global.asa file ) with

    <!--
       METADATA    
       TYPE="TypeLib"    
       NAME="Microsoft ActiveX Data Objects 2.5 Library"    
       UUID="{00000205-0000-0010-8000-00AA006D2EA4}"    
       VERSION="2.5"
    -->
    

    or

    you can simply copy a few constants from the adovbs file into your page to cover your needs. For example

    Const adCmdText = 1      'Evaluate as a textual definition    
    Const adCmdStoredProc = 4 'Evaluate as a stored procedure
    
    0 讨论(0)
  • 2021-01-20 07:47

    Relevant list of constants can be found here: http://www.4guysfromrolla.com/ASPScripts/PrintPage.asp?REF=%2Fwebtech%2Ffaq%2FBeginner%2Ffaq7.shtml

    I'll copy it here as well:

    '---- CursorTypeEnum Values ----
    Const adOpenForwardOnly = 0
    Const adOpenKeyset = 1
    Const adOpenDynamic = 2
    Const adOpenStatic = 3
    
    '---- CursorOptionEnum Values ----
    Const adHoldRecords = &H00000100
    Const adMovePrevious = &H00000200
    Const adAddNew = &H01000400
    Const adDelete = &H01000800
    Const adUpdate = &H01008000
    Const adBookmark = &H00002000
    Const adApproxPosition = &H00004000
    Const adUpdateBatch = &H00010000
    Const adResync = &H00020000
    

    Should be enough for inserting/selecting/updating records in database.

    0 讨论(0)
  • 2021-01-20 07:54

    Of course that the answer is "Forget about that- pound include those 400 or so boogers in there and don't ask stupid questions!" :)

    But since you insist:

    The best way is to encapsulate all data access function in one .ASP
    Let's call it dbHelper.asp

    Then put all the DB functions in there, like:

    ''// run a query and returns a disconnected recordset
    Function RunSQLReturnRS(sqlstmt, params())
        On Error Resume next
    
        ''//Create the ADO objects
        Dim rs , cmd
        Set rs = server.createobject("ADODB.Recordset")
        Set cmd = server.createobject("ADODB.Command")
    
        ''// Init the ADO objects  & the stored proc parameters
        cmd.ActiveConnection = GetConnectionString()
        cmd.CommandText = sqlstmt
        cmd.CommandType = adCmdText
    
        collectParams cmd, params
    
        ''//Execute the query for readonly
        rs.CursorLocation = adUseClient
        rs.Open cmd, , adOpenForwardOnly, adLockReadOnly
        If err.number > 0 then
            BuildErrorMessage()
            exit function
        end if
    
        ''//Disconnect the recordset
        Set cmd.ActiveConnection = Nothing
        Set cmd = Nothing
        Set rs.ActiveConnection = Nothing
    
        ''//Return the resultant recordset
        Set RunSQLReturnRS = rs
    
    End Function
    

    At that point, you know that all you ado constants are in this file and you can start replacing them as wished.

    0 讨论(0)
提交回复
热议问题