Hello, ADO(VB6) World!
Posted on 3月 4th, 2013 by cx20
ADO(VB6)
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 データベース |
ソースコード(VB6 + ADO + OLEDB + Jet データベース)
Option Explicit
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
Debug.Print rs(0).Name
Debug.Print "-------------------"
Debug.Print rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub |
Option Explicit
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
Debug.Print rs(0).Name
Debug.Print "-------------------"
Debug.Print rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub
ソースコード(VB6 + ADO + OLEDB + ACE データベース)
Option Explicit
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
Debug.Print rs(0).Name
Debug.Print "-------------------"
Debug.Print rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub |
Option Explicit
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
Debug.Print rs(0).Name
Debug.Print "-------------------"
Debug.Print rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub
ソースコード(VB6 + ADO + OLEDB + SQL Server)
Option Explicit
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
Debug.Print rs(0).Name
Debug.Print "-------------------"
Debug.Print rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub |
Option Explicit
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
Debug.Print rs(0).Name
Debug.Print "-------------------"
Debug.Print rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub
ソースコード(VB6 + ADO + OLEDB + Oracle)
Option Explicit
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
Debug.Print rs(0).Name
Debug.Print "-------------------"
Debug.Print rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub |
Option Explicit
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
Debug.Print rs(0).Name
Debug.Print "-------------------"
Debug.Print rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub
ソースコード(VB6 + ADO + ODBC + SQL Server)
Option Explicit
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
Debug.Print rs(0).Name
Debug.Print "-------------------"
Debug.Print rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub |
Option Explicit
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
Debug.Print rs(0).Name
Debug.Print "-------------------"
Debug.Print rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub
ソースコード(VB6 + ADO + ODBC + Oracle)
Option Explicit
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
Debug.Print rs(0).Name
Debug.Print "-------------------"
Debug.Print rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub |
Option Explicit
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
Debug.Print rs(0).Name
Debug.Print "-------------------"
Debug.Print rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub
ソースコード(VB6 + ADO + ODBC + MySQL)
Option Explicit
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
Debug.Print rs(0).Name
Debug.Print "-------------------"
Debug.Print rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub |
Option Explicit
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
Debug.Print rs(0).Name
Debug.Print "-------------------"
Debug.Print rs(0).Value
rs.MoveNext
Wend
rs.Close
cn.Close
End Sub
コンパイル方法
実行結果
Message
-----------------
Hello, ADO World! |
Message
-----------------
Hello, ADO World!
Tags: ADO
Categories: ADO, VB6