<%' 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" (本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)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 (本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)' BEGIN SUBS & FUNCTIONS SECTIONSub OpenConnectionSet objDC = Server.CreateObject("ADODB.Connection")objDC.ConnectionTimeout = 15objDC.CommandTimeout = 30objDC.Open DSN_NAME, DSN_USER, DSN_PASSEnd Sub (本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)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 "#" (本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)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") (本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)' Build Our SQL StatementsSqlString = "SELECT * FROM [" & sTableName & "]" (本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)' 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 & sCritDelimiterEnd If (本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)' If we're sorting - insert the ORDER BY clauseIf sSortOrder < "none" ThensSqlString = sSqlString & " ORDER BY [" & sSortField & "] " & sSortOrderEnd If (本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)sSqlString = sSqlString & ";" (本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)' Open the actual Recordset using a Forward Only Cursor in Read Only ModeobjRS.Open sSqlString, objDC, adOpenForwardOnly, adLockReadOnlyEnd SelectEnd Sub (本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)Sub CloseRecordsetobjRS.CloseSet objRS = NothingEnd Sub (本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)Sub CloseConnectionobjDC.CloseSet objDC = NothingEnd Sub (本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)Sub WriteTitle(sTitle)Response