Hello, ADO World!
Posted on 3月 23rd, 2012 by cx20
ADO
ADO(ActiveX Data Objects)は、マイクロソフト社が開発した COM ベースの DBMS 接続用 API である。
OLE DB プロバイダを介することで様々な DBMS への接続が可能となっている。
OLE DB プロバイダとしては、以下のようなプロバイダがある。いくつかが OS 標準で付属している他、追加インストールが可能である。
プロバイダ名 |
表示名 |
説明 |
MSDASQL |
Microsoft OLE DB Provider for ODBC |
ODBC データベース |
Microsoft.Jet.OLEDB.4.0 |
Microsoft OLE DB Provider for Microsoft Jet |
Microsoft Jet データベース |
Microsoft.ACE.OLEDB.12.0 |
Microsoft Office 12.0 Access Database Engine OLE DB Provider |
Microsoft Access データベース |
SQLOLEDB |
Microsoft OLE DB Provider for SQL Server |
Microsoft SQL Server |
SQLNCLI10 |
SQL Server Native Client 10.0 |
Microsoft SQL Server |
MSDAORA |
Microsoft OLE DB Provider for Oracle |
Oracle データベース |
ソースコード(VBScript + ADO + OLEDB + Jet データベース)
Option Explicit
Call Main()
Sub Main()
Dim cn
Dim rs
Set cn = CreateObject("ADODB.Connection")
cn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=.hello.mdb"
Set rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message")
While Not rs.EOF
WScript.Echo rs(0).Name
WScript.Echo "-------------------"
WScript.Echo rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub |
Option Explicit
Call Main()
Sub Main()
Dim cn
Dim rs
Set cn = CreateObject("ADODB.Connection")
cn.Open "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=.hello.mdb"
Set rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message")
While Not rs.EOF
WScript.Echo rs(0).Name
WScript.Echo "-------------------"
WScript.Echo rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub
ソースコード(VBScript + ADO + OLEDB + ACE データベース)
Option Explicit
Call Main()
Sub Main()
Dim cn
Dim rs
Set cn = CreateObject("ADODB.Connection")
cn.Open "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=.hello.accdb"
Set rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message")
While Not rs.EOF
WScript.Echo rs(0).Name
WScript.Echo "-------------------"
WScript.Echo rs(0).Value
rs.MoveNext
Wend
End Sub |
Option Explicit
Call Main()
Sub Main()
Dim cn
Dim rs
Set cn = CreateObject("ADODB.Connection")
cn.Open "PROVIDER=Microsoft.ACE.OLEDB.12.0;Data Source=.hello.accdb"
Set rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message")
While Not rs.EOF
WScript.Echo rs(0).Name
WScript.Echo "-------------------"
WScript.Echo rs(0).Value
rs.MoveNext
Wend
End Sub
ソースコード(VBScript + ADO + OLEDB + SQL Server)
Option Explicit
Call Main()
Sub Main()
Dim cn
Dim rs
Set cn = CreateObject("ADODB.Connection")
cn.Open "PROVIDER=SQLOLEDB;" & _
"SERVER=(local);DATABASE=master;", _
"sa", "P@ssW0rd"
Set rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message")
While Not rs.EOF
WScript.Echo rs(0).Name
WScript.Echo "-------------------"
WScript.Echo rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub |
Option Explicit
Call Main()
Sub Main()
Dim cn
Dim rs
Set cn = CreateObject("ADODB.Connection")
cn.Open "PROVIDER=SQLOLEDB;" & _
"SERVER=(local);DATABASE=master;", _
"sa", "P@ssW0rd"
Set rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message")
While Not rs.EOF
WScript.Echo rs(0).Name
WScript.Echo "-------------------"
WScript.Echo rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub
ソースコード(VBScript + ADO + OLEDB + Oracle)
Option Explicit
Call Main()
Sub Main()
Dim cn
Dim rs
Set cn = CreateObject("ADODB.Connection")
cn.Open "PROVIDER=MSDAORA;Data Source=ORCL", "scott", "tiger"
Set rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message FROM DUAL")
While Not rs.EOF
WScript.Echo rs(0).Name
WScript.Echo "-------------------"
WScript.Echo rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub |
Option Explicit
Call Main()
Sub Main()
Dim cn
Dim rs
Set cn = CreateObject("ADODB.Connection")
cn.Open "PROVIDER=MSDAORA;Data Source=ORCL", "scott", "tiger"
Set rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message FROM DUAL")
While Not rs.EOF
WScript.Echo rs(0).Name
WScript.Echo "-------------------"
WScript.Echo rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub
ソースコード(VBScript + ADO + ODBC + SQL Server)
Option Explicit
Call Main()
Sub Main()
Dim cn
Dim rs
Set cn = CreateObject("ADODB.Connection")
cn.Open "PROVIDER=MSDASQL;Driver={SQL Server};" & _
"SERVER=(local);DATABASE=master;", _
"sa", "P@ssW0rd"
Set rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message")
While Not rs.EOF
WScript.Echo rs(0).Name
WScript.Echo "-------------------"
WScript.Echo rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub |
Option Explicit
Call Main()
Sub Main()
Dim cn
Dim rs
Set cn = CreateObject("ADODB.Connection")
cn.Open "PROVIDER=MSDASQL;Driver={SQL Server};" & _
"SERVER=(local);DATABASE=master;", _
"sa", "P@ssW0rd"
Set rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message")
While Not rs.EOF
WScript.Echo rs(0).Name
WScript.Echo "-------------------"
WScript.Echo rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub
ソースコード(VBScript + ADO + ODBC + Oracle)
Option Explicit
Call Main()
Sub Main()
Dim cn
Dim rs
Set cn = CreateObject("ADODB.Connection")
cn.Open "PROVIDER=MSDASQL;Driver={Microsoft ODBC for Oracle};Server=ORCL", _
"scott", "tiger"
Set rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message FROM DUAL")
While Not rs.EOF
WScript.Echo rs(0).Name
WScript.Echo "-------------------"
WScript.Echo rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub |
Option Explicit
Call Main()
Sub Main()
Dim cn
Dim rs
Set cn = CreateObject("ADODB.Connection")
cn.Open "PROVIDER=MSDASQL;Driver={Microsoft ODBC for Oracle};Server=ORCL", _
"scott", "tiger"
Set rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message FROM DUAL")
While Not rs.EOF
WScript.Echo rs(0).Name
WScript.Echo "-------------------"
WScript.Echo rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub
ソースコード(VBScript + ADO + ODBC + MySQL)
Option Explicit
Call Main()
Sub Main()
Dim cn
Dim rs
Set cn = CreateObject("ADODB.Connection")
cn.Open "PROVIDER=MSDASQL;Driver={MySQL ODBC 5.1 Driver};Server=localhost", _
"root", "P@ssW0rd"
Set rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message")
While Not rs.EOF
WScript.Echo rs(0).Name
WScript.Echo "-------------------"
WScript.Echo rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub |
Option Explicit
Call Main()
Sub Main()
Dim cn
Dim rs
Set cn = CreateObject("ADODB.Connection")
cn.Open "PROVIDER=MSDASQL;Driver={MySQL ODBC 5.1 Driver};Server=localhost", _
"root", "P@ssW0rd"
Set rs = cn.Execute("SELECT 'Hello, ADO World!' AS Message")
While Not rs.EOF
WScript.Echo rs(0).Name
WScript.Echo "-------------------"
WScript.Echo rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub
実行方法(Windows)
C:¥> CScript //Nologo Hello.vbs |
C:¥> CScript //Nologo Hello.vbs
実行結果
Message
-----------------
Hello, ADO World! |
Message
-----------------
Hello, ADO World!
Tags: ADO
Categories: ADO, library, OLE DB, SQL, SQL Server