<%' BEGIN USER CONSTANTS' To just use a DSN, the format is shown on the next line:'Const DSN_NAME = "DSN=ASP101email"' Two other samples I used it with. Left in as syntax examples for DSN-less connections'Const DSN_NAME = "DBQ=C:InetPubwwwrootasp101samplesdatabase.mdb;Driver={Microsoft Access Driver (*.mdb)};DriverId=25"'Const DSN_NAME = "DBQ=C:InetPubdatabasedonations.mdb;Driver={Microsoft Access Driver (*.mdb)};DriverId=25" Dim DSN_NAMEDSN_NAME = "DBQ=" & Server.MapPath("db_dsn.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;"Const DSN_USER = "username"Const DSN_PASS = "password"' Ok, I know these are poorly named constants, so sue me!' This script can be used without actually setting up a DSN, so' DSN_NAME as well as the other two constants should really be named' something more generic like CONNECTION_STRING, CONNECTION_USER, and' CONNECTION_PASS, but I did it this way without really thinking about' it and I'm too lazy to change it now. If it bothers you, you do it!' END USER CONSTANTS ' BEGIN SUBS & FUNCTIONS SECTIONSub OpenConnectionSet objDC = Server.CreateObject("ADODB.Connection")objDC.ConnectionTimeout = 15objDC.CommandTimeout = 30objDC.Open DSN_NAME, DSN_USER, DSN_PASSEnd Sub Sub OpenRecordset(sType)Dim sSqlString ' as String - building area for SQL queryDim sCritOperator ' as String - basically "=" or "LIKE"Dim sCritDelimiter ' as String - parameter delimiter "", "'", or "#" Set objRS = Server.CreateObject("ADODB.Recordset")Select Case sTypeCase "ListTables" ' Open RS of the Tables in the DBSet objRS = objDC.OpenSchema(adSchemaTables)Case "ViewTable" ' Open the Selected TableSet objRS = Server.CreateObject("ADODB.Recordset")objRS.Open "[" & sTableName & "]", objDC, adOpenForwardOnly, adLockReadOnlyCase "DrillDown" ' Open the Recordset built by the selected optionsSet objRS = Server.CreateObject("ADODB.Recordset") ' Build Our SQL Statement(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)sSqlString = "SELECT * FROM [" & sTableName & "]" ' If we're limiting records returned - insert the WHERE Clause into the SQLIf sCritField < "" Then' Figure out if we're dealinh with Numeric, Date, or String ValuesSelect Case iCritDataTypeCase adSmallInt, adInteger, adSingle, adDouble, adDecimal, adTinyInt, adUnsignedTinyInt, adUnsignedSmallInt, adUnsignedInt, adBigInt, adUnsignedBigInt, adBinary, adNumeric, adVarBinary, adLongVarBinary, adCurrency, adBooleansCritOperator = "="sCritDelimiter = ""Case adDate, adDBDate, adDBTime, adDBTimeStampsCritOperator = "="sCritDelimiter = "#"Case adBSTR, adChar, adWChar, adVarChar, adLongVarChar, adVarWChar, adLongVarWCharsCritOperator = "LIKE"sCritDelimiter = "'"End SelectsSqlString = sSqlString & " WHERE [" & sCritField & "] " & sCritOperator & " " & sCritDelimiter & sCritValue & sCritDelimiter(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)End If ' If we're sorting - insert the ORDER BY clauseIf sSortOrder < "none" ThensSqlString = sSqlString & " ORDER BY [" & sSortField & "] " & sSortOrderEnd If sSqlString = sSqlString & ";" ' Open the actual Recordset using a Forward Only Cursor in Read Only ModeobjRS.Open sSqlString, objDC, adOpenForwardOnly, adLockReadOnlyEnd SelectEnd Sub Sub CloseRecordsetobjRS.CloseSet objRS = NothingEnd Sub Sub CloseConnectionobjDC.CloseSet objDC = NothingEnd Sub Sub WriteTitle(sTitle)Response