Hello, ADO.NET(Nemerle) World!
Posted on 2月 27th, 2013 by cx20
ADO.NET(Nemerle)
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 |
ソースコード(Nemerle + ADO.NET + OLE DB + Jet データベース)
using System;
using System.Data.OleDb;
class Hello
{
public static Main() : void {
def conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=hello.mdb";
def sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message";
def con = OleDbConnection(conStr);
def cmd = OleDbCommand(sqlStr, con);
con.Open();
def reader = cmd.ExecuteReader();
while( reader.Read() )
{
Console.WriteLine( reader.GetName(0) );
Console.WriteLine( "---------------------" );
Console.WriteLine( reader[0] );
}
reader.Close();
con.Close();
}
} |
using System;
using System.Data.OleDb;
class Hello
{
public static Main() : void {
def conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=hello.mdb";
def sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message";
def con = OleDbConnection(conStr);
def cmd = OleDbCommand(sqlStr, con);
con.Open();
def reader = cmd.ExecuteReader();
while( reader.Read() )
{
Console.WriteLine( reader.GetName(0) );
Console.WriteLine( "---------------------" );
Console.WriteLine( reader[0] );
}
reader.Close();
con.Close();
}
}
ソースコード(Nemerle + ADO.NET + OLE DB + ACE データベース)
using System;
using System.Data.OleDb;
class Hello
{
public static Main() : void {
def conStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=hello.accdb;";
def sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message";
def con = OleDbConnection(conStr);
def cmd = OleDbCommand(sqlStr, con);
con.Open();
def reader = cmd.ExecuteReader();
while( reader.Read() )
{
Console.WriteLine( reader.GetName(0) );
Console.WriteLine( "---------------------" );
Console.WriteLine( reader[0] );
}
reader.Close();
con.Close();
}
} |
using System;
using System.Data.OleDb;
class Hello
{
public static Main() : void {
def conStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=hello.accdb;";
def sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message";
def con = OleDbConnection(conStr);
def cmd = OleDbCommand(sqlStr, con);
con.Open();
def reader = cmd.ExecuteReader();
while( reader.Read() )
{
Console.WriteLine( reader.GetName(0) );
Console.WriteLine( "---------------------" );
Console.WriteLine( reader[0] );
}
reader.Close();
con.Close();
}
}
ソースコード(Nemerle + ADO.NET + SQL Server)
using System;
using System.Data.SqlClient;
class Hello
{
public static Main() : void {
def conStr = "SERVER=(local);DATABASE=master;UID=sa;PWD=P@ssW0rd";
def sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message";
def con = SqlConnection(conStr);
def cmd = SqlCommand(sqlStr, con);
con.Open();
def reader = cmd.ExecuteReader();
while( reader.Read() )
{
Console.WriteLine( reader.GetName(0) );
Console.WriteLine( "---------------------" );
Console.WriteLine( reader[0] );
}
reader.Close();
con.Close();
}
} |
using System;
using System.Data.SqlClient;
class Hello
{
public static Main() : void {
def conStr = "SERVER=(local);DATABASE=master;UID=sa;PWD=P@ssW0rd";
def sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message";
def con = SqlConnection(conStr);
def cmd = SqlCommand(sqlStr, con);
con.Open();
def reader = cmd.ExecuteReader();
while( reader.Read() )
{
Console.WriteLine( reader.GetName(0) );
Console.WriteLine( "---------------------" );
Console.WriteLine( reader[0] );
}
reader.Close();
con.Close();
}
}
ソースコード(Nemerle + ADO.NET + Oracle)
using System;
using System.Data.OracleClient;
class Hello
{
public static Main() : void {
def conStr = "Data Source=ORCL;User ID=scott;Password=tiger";
def sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message FROM DUAL";
def con = OracleConnection(conStr);
def cmd = OracleCommand(sqlStr, con);
con.Open();
def reader = cmd.ExecuteReader();
while( reader.Read() )
{
Console.WriteLine( reader.GetName(0) );
Console.WriteLine( "---------------------" );
Console.WriteLine( reader[0] );
}
reader.Close();
con.Close();
}
} |
using System;
using System.Data.OracleClient;
class Hello
{
public static Main() : void {
def conStr = "Data Source=ORCL;User ID=scott;Password=tiger";
def sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message FROM DUAL";
def con = OracleConnection(conStr);
def cmd = OracleCommand(sqlStr, con);
con.Open();
def reader = cmd.ExecuteReader();
while( reader.Read() )
{
Console.WriteLine( reader.GetName(0) );
Console.WriteLine( "---------------------" );
Console.WriteLine( reader[0] );
}
reader.Close();
con.Close();
}
}
ソースコード(Nemerle + ADO.NET + ODBC + MySQL)
using System;
using System.Data.Odbc;
class Hello
{
public static Main() : void {
def conStr = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;UID=root;PWD=P@ssW0rd";
def sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message";
def con = OdbcConnection(conStr);
def cmd = OdbcCommand(sqlStr, con);
con.Open();
def reader = cmd.ExecuteReader();
while( reader.Read() )
{
Console.WriteLine( reader.GetName(0) );
Console.WriteLine( "---------------------" );
Console.WriteLine( reader[0] );
}
reader.Close();
con.Close();
}
} |
using System;
using System.Data.Odbc;
class Hello
{
public static Main() : void {
def conStr = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;UID=root;PWD=P@ssW0rd";
def sqlStr = "SELECT 'Hello, ADO.NET World!' AS Message";
def con = OdbcConnection(conStr);
def cmd = OdbcCommand(sqlStr, con);
con.Open();
def reader = cmd.ExecuteReader();
while( reader.Read() )
{
Console.WriteLine( reader.GetName(0) );
Console.WriteLine( "---------------------" );
Console.WriteLine( reader[0] );
}
reader.Close();
con.Close();
}
}
コンパイル方法(32bit OLE DB 使用時)
C:¥> ncc -o Hello.exe -r:System.Data -platform:x86 Hello.n |
C:¥> ncc -o Hello.exe -r:System.Data -platform:x86 Hello.n
コンパイル方法(64bit OLE DB 使用時)
C:¥> ncc -o Hello.exe -r:System.Data -platform:x86 Hello.n |
C:¥> ncc -o Hello.exe -r:System.Data -platform:x86 Hello.n
コンパイル方法(上記以外)
C:¥> ncc -o Hello.exe -r:System.Data Hello.n |
C:¥> ncc -o Hello.exe -r:System.Data Hello.n
実行結果
Message
---------------------
Hello, ADO.NET World! |
Message
---------------------
Hello, ADO.NET World!
Tags: ADO.NET
Categories: .NET, ADO.NET, Nemerle