不通过数据源完全控制MDB数据库

Avivi_meng

Avivi_meng

2016-01-29 20:11

不通过数据源完全控制MDB数据库,不通过数据源完全控制MDB数据库

<%

' 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_NAME

DSN_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 SECTION

Sub OpenConnection

Set objDC = Server.CreateObject("ADODB.Connection")

objDC.ConnectionTimeout = 15

objDC.CommandTimeout = 30

objDC.Open DSN_NAME, DSN_USER, DSN_PASS

End Sub

 

Sub OpenRecordset(sType)

Dim sSqlString ' as String - building area for SQL query

Dim sCritOperator ' as String - basically "=" or "LIKE"

Dim sCritDelimiter ' as String - parameter delimiter "", "'", or "#"

 

Set objRS = Server.CreateObject("ADODB.Recordset")

Select Case sType

Case "ListTables" ' Open RS of the Tables in the DB

Set objRS = objDC.OpenSchema(adSchemaTables)

Case "ViewTable"  ' Open the Selected Table

Set objRS = Server.CreateObject("ADODB.Recordset")

objRS.Open "[" & sTableName & "]", objDC, adOpenForwardOnly, adLockReadOnly

Case "DrillDown"  ' Open the Recordset built by the selected options

Set 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 SQL

If sCritField < "" Then

' Figure out if we're dealinh with Numeric, Date, or String Values

Select Case iCritDataType

Case adSmallInt, adInteger, adSingle, adDouble, adDecimal, adTinyInt, adUnsignedTinyInt, adUnsignedSmallInt, adUnsignedInt, adBigInt, adUnsignedBigInt, adBinary, adNumeric, adVarBinary, adLongVarBinary, adCurrency, adBoolean

sCritOperator = "="

sCritDelimiter = ""

Case adDate, adDBDate, adDBTime, adDBTimeStamp

sCritOperator = "="

sCritDelimiter = "#"

Case adBSTR, adChar, adWChar, adVarChar, adLongVarChar, adVarWChar, adLongVarWChar

sCritOperator = "LIKE"

sCritDelimiter = "'"

End Select

sSqlString = sSqlString & " WHERE [" & sCritField & "] " & sCritOperator & " " & sCritDelimiter & sCritValue & sCritDelimiter

(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/asp/)

End If

 

' If we're sorting - insert the ORDER BY clause

If sSortOrder < "none" Then

sSqlString = sSqlString & " ORDER BY [" & sSortField & "] " & sSortOrder

End If

 

sSqlString = sSqlString & ";"

 

' Open the actual Recordset using a Forward Only Cursor in Read Only Mode

objRS.Open sSqlString, objDC, adOpenForwardOnly, adLockReadOnly

End Select

End Sub

 

Sub CloseRecordset

objRS.Close

Set objRS = Nothing

End Sub

 

Sub CloseConnection

objDC.Close

Set objDC = Nothing

End Sub

 

Sub WriteTitle(sTitle)

Response

展开更多 50%)
分享

猜你喜欢

不通过数据源完全控制MDB数据库

ASP
不通过数据源完全控制MDB数据库

Jsp连接Access数据库(不通过建立ODBC数据源的方法)

Web开发
Jsp连接Access数据库(不通过建立ODBC数据源的方法)

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

不用数据源打开数据库(DSNless connection)

ASP
不用数据源打开数据库(DSNless connection)

VB与大型数据库无数据源的连接

编程语言 网络编程
VB与大型数据库无数据源的连接

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

通过VS中的数据源选择对话框简单实现数据库连接配置

Web开发
通过VS中的数据源选择对话框简单实现数据库连接配置

通过VS中的数据源选择对话框简单实现数据库连接配置[图]

编程语言 网络编程
通过VS中的数据源选择对话框简单实现数据库连接配置[图]

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

Photoshop鼠绘教程:制作超绚游戏家族徽标

Photoshop鼠绘教程:制作超绚游戏家族徽标

PS鼠绘悠闲的青春生活插画

PS鼠绘悠闲的青春生活插画
下拉加载更多内容 ↓