本文记录了通过VBScript语言将ADO连接Access、Oracle、Excel、SQL Server数据库封装成函数,便于以后调用,对数据库进行增、删、改、查。
1 函数封装
1.1 初始化数据库
'初始化数据库
'参数:数据库类型(Oracle, Access, Excel), 实例名,数据库名, 密码,数据源
'Oracle数据库无需填写最后一个参数,Access数据库只需填写最后一个参数
'返回:登录状态,1-成功,0-失败
Function InitDateBase(ByVal dbType, ByVal dbServer, ByVal dbUID, ByVal dbPwd, ByVal dbSource)
Set oConn = CreateObject("ADODB.Connection")
Select Case UCase(dbType)
Case "ORACLE"
oConn.ConnectionString = "Driver={Microsoft ODBC for Oracle}; Server=" & dbServer & ";UID = " & dbUID & ";Pwd = " & dbPwd
oConn.Open
Case "SQLSERVER"
oConn.ConnectionString = "Driver={ODBC Driver 17 for SQL Server};Server= " & dbServer &" ;Database=" & dbSource & ";UID=" & dbUID & ";pwd=" & dbPwd & ";"
oConn.Open
Case "ACCESS"
oConn.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0; Data Source=" & dbSource
oConn.Open
Case "EXCLE"
IsHeader = "YES"
oConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;