Hello, ADO.NET(IronScheme) World!
Posted on 2月 15th, 2013 by cx20
ADO.NET(IronScheme)
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 |
ソースコード(IronScheme + ADO.NET + OLE DB + Jet データベース)
(import
(rnrs)
(ironscheme clr)
)
(clr-reference System)
(clr-reference System.Data)
(clr-using System)
(clr-using System.Data.OleDb)
(begin
(define conStr "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=hello.mdb")
(define sqlStr "SELECT 'Hello, ADO.NET World!' AS Message")
(define con (clr-new OleDbConnection conStr))
(define cmd (clr-new OleDbCommand sqlStr con))
(clr-call OleDbConnection Open con)
(define reader (clr-call OleDbCommand ExecuteReader cmd))
(if (clr-call OleDbDataReader Read reader)
(begin
(clr-static-call System.Console WriteLine (clr-call OleDbDataReader GetName reader 0))
(clr-static-call System.Console WriteLine "---------------------")
(clr-static-call System.Console WriteLine (clr-call OleDbDataReader GetValue reader 0))
)
)
(clr-call OleDbDataReader Close reader)
(clr-call OleDbConnection Close con)
) |
(import
(rnrs)
(ironscheme clr)
)
(clr-reference System)
(clr-reference System.Data)
(clr-using System)
(clr-using System.Data.OleDb)
(begin
(define conStr "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=hello.mdb")
(define sqlStr "SELECT 'Hello, ADO.NET World!' AS Message")
(define con (clr-new OleDbConnection conStr))
(define cmd (clr-new OleDbCommand sqlStr con))
(clr-call OleDbConnection Open con)
(define reader (clr-call OleDbCommand ExecuteReader cmd))
(if (clr-call OleDbDataReader Read reader)
(begin
(clr-static-call System.Console WriteLine (clr-call OleDbDataReader GetName reader 0))
(clr-static-call System.Console WriteLine "---------------------")
(clr-static-call System.Console WriteLine (clr-call OleDbDataReader GetValue reader 0))
)
)
(clr-call OleDbDataReader Close reader)
(clr-call OleDbConnection Close con)
)
ソースコード(IronScheme + ADO.NET + OLE DB + ACE データベース)
(import
(rnrs)
(ironscheme clr)
)
(clr-reference System)
(clr-reference System.Data)
(clr-using System)
(clr-using System.Data.OleDb)
(begin
(define conStr "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=hello.accdb")
(define sqlStr "SELECT 'Hello, ADO.NET World!' AS Message")
(define con (clr-new OleDbConnection conStr))
(define cmd (clr-new OleDbCommand sqlStr con))
(clr-call OleDbConnection Open con)
(define reader (clr-call OleDbCommand ExecuteReader cmd))
(if (clr-call OleDbDataReader Read reader)
(begin
(clr-static-call System.Console WriteLine (clr-call OleDbDataReader GetName reader 0))
(clr-static-call System.Console WriteLine "---------------------")
(clr-static-call System.Console WriteLine (clr-call OleDbDataReader GetValue reader 0))
)
)
(clr-call OleDbDataReader Close reader)
(clr-call OleDbConnection Close con)
) |
(import
(rnrs)
(ironscheme clr)
)
(clr-reference System)
(clr-reference System.Data)
(clr-using System)
(clr-using System.Data.OleDb)
(begin
(define conStr "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=hello.accdb")
(define sqlStr "SELECT 'Hello, ADO.NET World!' AS Message")
(define con (clr-new OleDbConnection conStr))
(define cmd (clr-new OleDbCommand sqlStr con))
(clr-call OleDbConnection Open con)
(define reader (clr-call OleDbCommand ExecuteReader cmd))
(if (clr-call OleDbDataReader Read reader)
(begin
(clr-static-call System.Console WriteLine (clr-call OleDbDataReader GetName reader 0))
(clr-static-call System.Console WriteLine "---------------------")
(clr-static-call System.Console WriteLine (clr-call OleDbDataReader GetValue reader 0))
)
)
(clr-call OleDbDataReader Close reader)
(clr-call OleDbConnection Close con)
)
ソースコード(IronScheme + ADO.NET + SQL Server)
(import
(rnrs)
(ironscheme clr)
)
(clr-reference System)
(clr-reference System.Data)
(clr-using System)
(clr-using System.Data.SqlClient)
(begin
(define conStr "SERVER=(local);DATABASE=master;UID=sa;PWD=P@ssW0rd;")
(define sqlStr "SELECT 'Hello, ADO.NET World!' AS Message")
(define con (clr-new SqlConnection conStr))
(define cmd (clr-new SqlCommand sqlStr con))
(clr-call SqlConnection Open con)
(define reader (clr-call SqlCommand ExecuteReader cmd))
(if (clr-call SqlDataReader Read reader)
(begin
(clr-static-call System.Console WriteLine (clr-call SqlDataReader GetName reader 0))
(clr-static-call System.Console WriteLine "---------------------")
(clr-static-call System.Console WriteLine (clr-call SqlDataReader GetValue reader 0))
)
)
(clr-call SqlDataReader Close reader)
(clr-call SqlConnection Close con)
) |
(import
(rnrs)
(ironscheme clr)
)
(clr-reference System)
(clr-reference System.Data)
(clr-using System)
(clr-using System.Data.SqlClient)
(begin
(define conStr "SERVER=(local);DATABASE=master;UID=sa;PWD=P@ssW0rd;")
(define sqlStr "SELECT 'Hello, ADO.NET World!' AS Message")
(define con (clr-new SqlConnection conStr))
(define cmd (clr-new SqlCommand sqlStr con))
(clr-call SqlConnection Open con)
(define reader (clr-call SqlCommand ExecuteReader cmd))
(if (clr-call SqlDataReader Read reader)
(begin
(clr-static-call System.Console WriteLine (clr-call SqlDataReader GetName reader 0))
(clr-static-call System.Console WriteLine "---------------------")
(clr-static-call System.Console WriteLine (clr-call SqlDataReader GetValue reader 0))
)
)
(clr-call SqlDataReader Close reader)
(clr-call SqlConnection Close con)
)
ソースコード(IronScheme + ADO.NET + Oracle)
(import
(rnrs)
(ironscheme clr)
)
(clr-reference System)
(clr-reference System.Data)
(clr-using System)
(clr-using System.Data.OracleClient)
(begin
(define conStr "Data Source=ORCL;User ID=scott;Password=tiger;")
(define sqlStr "SELECT 'Hello, ADO.NET World!' AS Message FROM DUAL")
(define con (clr-new OracleConnection conStr))
(define cmd (clr-new OracleCommand sqlStr con))
(clr-call OracleConnection Open con)
(define reader (clr-call OracleCommand ExecuteReader cmd))
(if (clr-call OracleDataReader Read reader)
(begin
(clr-static-call System.Console WriteLine (clr-call OracleDataReader GetName reader 0))
(clr-static-call System.Console WriteLine "---------------------")
(clr-static-call System.Console WriteLine (clr-call OracleDataReader GetValue reader 0))
)
)
(clr-call OracleDataReader Close reader)
(clr-call OracleConnection Close con)
) |
(import
(rnrs)
(ironscheme clr)
)
(clr-reference System)
(clr-reference System.Data)
(clr-using System)
(clr-using System.Data.OracleClient)
(begin
(define conStr "Data Source=ORCL;User ID=scott;Password=tiger;")
(define sqlStr "SELECT 'Hello, ADO.NET World!' AS Message FROM DUAL")
(define con (clr-new OracleConnection conStr))
(define cmd (clr-new OracleCommand sqlStr con))
(clr-call OracleConnection Open con)
(define reader (clr-call OracleCommand ExecuteReader cmd))
(if (clr-call OracleDataReader Read reader)
(begin
(clr-static-call System.Console WriteLine (clr-call OracleDataReader GetName reader 0))
(clr-static-call System.Console WriteLine "---------------------")
(clr-static-call System.Console WriteLine (clr-call OracleDataReader GetValue reader 0))
)
)
(clr-call OracleDataReader Close reader)
(clr-call OracleConnection Close con)
)
ソースコード(IronScheme + ADO.NET + ODBC + MySQL)
(import
(rnrs)
(ironscheme clr)
)
(clr-reference System)
(clr-reference System.Data)
(clr-using System)
(clr-using System.Data.Odbc)
(begin
(define conStr "Driver={MySQL ODBC 5.1 Driver};Server=localhost;UID=root;PWD=P@ssW0rd")
(define sqlStr "SELECT 'Hello, ADO.NET World!' AS MessageL")
(define con (clr-new OdbcConnection conStr))
(define cmd (clr-new OdbcCommand sqlStr con))
(clr-call OdbcConnection Open con)
(define reader (clr-call OdbcCommand ExecuteReader cmd))
(if (clr-call OdbcDataReader Read reader)
(begin
(clr-static-call System.Console WriteLine (clr-call OdbcDataReader GetName reader 0))
(clr-static-call System.Console WriteLine "---------------------")
(clr-static-call System.Console WriteLine (clr-call OdbcDataReader GetValue reader 0))
)
)
(clr-call OdbcDataReader Close reader)
(clr-call OdbcConnection Close con)
) |
(import
(rnrs)
(ironscheme clr)
)
(clr-reference System)
(clr-reference System.Data)
(clr-using System)
(clr-using System.Data.Odbc)
(begin
(define conStr "Driver={MySQL ODBC 5.1 Driver};Server=localhost;UID=root;PWD=P@ssW0rd")
(define sqlStr "SELECT 'Hello, ADO.NET World!' AS MessageL")
(define con (clr-new OdbcConnection conStr))
(define cmd (clr-new OdbcCommand sqlStr con))
(clr-call OdbcConnection Open con)
(define reader (clr-call OdbcCommand ExecuteReader cmd))
(if (clr-call OdbcDataReader Read reader)
(begin
(clr-static-call System.Console WriteLine (clr-call OdbcDataReader GetName reader 0))
(clr-static-call System.Console WriteLine "---------------------")
(clr-static-call System.Console WriteLine (clr-call OdbcDataReader GetValue reader 0))
)
)
(clr-call OdbcDataReader Close reader)
(clr-call OdbcConnection Close con)
)
実行方法
実行結果
Message
---------------------
Hello, ADO.NET World! |
Message
---------------------
Hello, ADO.NET World!
Tags: ADO.NET
Categories: ADO.NET, IronScheme