Hello, ADO.NET(Cobra) World!
Posted on 2月 21st, 2013 by cx20
ADO.NET(Cobra)
ADO.NET(ActiveX Data Objects .NET)は、ADO の後継で .NET ベースの DBMS 接続用 API である。
.NET データプロバイダを介することで様々な DBMS への接続が可能となっている。
.NET Framework 標準で使用できる .NET データプロバイダとしては、以下のようなプロバイダがある。
データプロバイダ名 |
説明 |
System.Data.SqlClient |
Microsoft SQL Server |
System.Data.OleDb |
OLE DB |
System.Data.Odbc |
ODBC |
System.Data.OracleClient |
Oracle |
ソースコード(Cobra + ADO.NET + OLE DB + Jet データベース)
use System
use System.Data
use System.Data.OleDb
class Program
def main is shared
conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=hello.mdb;"
sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message"
con = OleDbConnection(conStr)
cmd = OleDbCommand(sqlStr, con)
con.open()
reader = cmd.executeReader()
while reader.read()
Console.writeLine( reader.getName(0) )
Console.writeLine( "---------------------" )
Console.writeLine( reader.getValue(0) )
reader.close()
con.close() |
use System
use System.Data
use System.Data.OleDb
class Program
def main is shared
conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=hello.mdb;"
sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message"
con = OleDbConnection(conStr)
cmd = OleDbCommand(sqlStr, con)
con.open()
reader = cmd.executeReader()
while reader.read()
Console.writeLine( reader.getName(0) )
Console.writeLine( "---------------------" )
Console.writeLine( reader.getValue(0) )
reader.close()
con.close()
ソースコード(Cobra + ADO.NET + OLE DB + ACE データベース)
use System
use System.Data
use System.Data.OleDb
class Program
def main is shared
conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=hello.mdb;"
sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message"
con = OleDbConnection(conStr)
cmd = OleDbCommand(sqlStr, con)
con.open()
reader = cmd.executeReader()
while reader.read()
Console.writeLine( reader.getName(0) )
Console.writeLine( "---------------------" )
Console.writeLine( reader.getValue(0) )
reader.close()
con.close() |
use System
use System.Data
use System.Data.OleDb
class Program
def main is shared
conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=hello.mdb;"
sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message"
con = OleDbConnection(conStr)
cmd = OleDbCommand(sqlStr, con)
con.open()
reader = cmd.executeReader()
while reader.read()
Console.writeLine( reader.getName(0) )
Console.writeLine( "---------------------" )
Console.writeLine( reader.getValue(0) )
reader.close()
con.close()
ソースコード(Cobra + ADO.NET + SQL Server)
use System
use System.Data
use System.Data.SqlClient
class Program
def main is shared
conStr = "SERVER=(local);DATABASE=master;UID=sa;PWD=P@ssW0rd;"
sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message"
con = SqlConnection(conStr)
cmd = SqlCommand(sqlStr, con)
con.open()
reader = cmd.executeReader()
while reader.read()
Console.writeLine( reader.getName(0) )
Console.writeLine( "---------------------" )
Console.writeLine( reader.getValue(0) )
reader.close()
con.close() |
use System
use System.Data
use System.Data.SqlClient
class Program
def main is shared
conStr = "SERVER=(local);DATABASE=master;UID=sa;PWD=P@ssW0rd;"
sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message"
con = SqlConnection(conStr)
cmd = SqlCommand(sqlStr, con)
con.open()
reader = cmd.executeReader()
while reader.read()
Console.writeLine( reader.getName(0) )
Console.writeLine( "---------------------" )
Console.writeLine( reader.getValue(0) )
reader.close()
con.close()
ソースコード(Cobra + ADO.NET + Oracle)
use System
use System.Data
use System.Data.OracleClient
class Program
def main is shared
conStr = "Data Source=ORCL;User ID=scott;Password=tiger"
sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message FROM DUAL"
con = OracleConnection(conStr)
cmd = OracleCommand(sqlStr, con)
con.open()
reader = cmd.executeReader()
while reader.read()
Console.writeLine( reader.getName(0) )
Console.writeLine( "---------------------" )
Console.writeLine( reader.getValue(0) )
reader.close()
con.close() |
use System
use System.Data
use System.Data.OracleClient
class Program
def main is shared
conStr = "Data Source=ORCL;User ID=scott;Password=tiger"
sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message FROM DUAL"
con = OracleConnection(conStr)
cmd = OracleCommand(sqlStr, con)
con.open()
reader = cmd.executeReader()
while reader.read()
Console.writeLine( reader.getName(0) )
Console.writeLine( "---------------------" )
Console.writeLine( reader.getValue(0) )
reader.close()
con.close()
ソースコード(Cobra + ADO.NET + ODBC + MySQL)
use System
use System.Data
use System.Data.Odbc
class Program
def main is shared
conStr = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;UID=root;PWD=P@ssW0rd"
sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message"
con = OdbcConnection(conStr)
cmd = OdbcCommand(sqlStr, con)
con.open()
reader = cmd.executeReader()
while reader.read()
Console.writeLine( reader.getName(0) )
Console.writeLine( "---------------------" )
Console.writeLine( reader.getValue(0) )
reader.close()
con.close() |
use System
use System.Data
use System.Data.Odbc
class Program
def main is shared
conStr = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;UID=root;PWD=P@ssW0rd"
sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message"
con = OdbcConnection(conStr)
cmd = OdbcCommand(sqlStr, con)
con.open()
reader = cmd.executeReader()
while reader.read()
Console.writeLine( reader.getName(0) )
Console.writeLine( "---------------------" )
Console.writeLine( reader.getValue(0) )
reader.close()
con.close()
コンパイル方法(32bit OLE DB 使用時)
C:¥> cobra -compile -sharp-args:"/platform:x86" Hello.cobra |
C:¥> cobra -compile -sharp-args:"/platform:x86" Hello.cobra
コンパイル方法(上記以外)
C:¥> cobra -compile Hello.cobra |
C:¥> cobra -compile Hello.cobra
実行結果
Message
---------------------
Hello, ADO.NET World! |
Message
---------------------
Hello, ADO.NET World!
Tags: ADO.NET
Categories: .NET, ADO.NET, Cobra