Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;
Using System.Data.Odbc;
Using System.Data.OleDb;
Namespace testing ODBC and OLE
{
Class Program
{
static void Main (string[] args)
{
Odbc
String connstring = "Aaaaas";
OdbcConnection conn = new OdbcConnection (connstring);
Conn. Open ();
OdbcCommand command = conn. CreateCommand ();
Command.commandtext = "SELECT * FROM table";
OdbcDataReader read = command. ExecuteReader (System.Data.CommandBehavior.CloseConnection);
while (read. Read ())
//{
Console.WriteLine ("Data: name {0}", reader.) GetString (1));
Console.WriteLine ("Data: name {0}, age {1}, gender {2}", read.) GetString (1), read. GetValue (2), read. GetValue (3));
//}
Console.read ();
OLE DB
Connect to an Access database
Microsoft.Jet.OLEDB.4.0 (hereinafter referred to as the Jet engine)
String oledbconnstring = @ "Provider=Microsoft.Jet.OLEDB.4.0;Data source=e:\programme\ work \mypraticework\ test ODBC with OLE \ Test ODBC and Ole\bin\debug\emr.mdb ";
OleDbConnection connole = new OleDbConnection (oledbconnstring);
Connole.open ();
OleDbCommand commandole = Connole.createcommand ();
Commandole.commandtext = "SELECT * from Emr_patients";
OleDbDataReader reader = Commandole.executereader (System.Data.CommandBehavior.CloseConnection);
if (reader. Read ())
//{
Console.WriteLine ("Data: name {0}", reader.) GetString (0));
Console.WriteLine ("Data: name {0}, age {1}, gender {2}", reader.) GetString (0), reader. GetString (1), reader. GetString (2));
//}
Console.read ();
MICROSOFT.ACE.OLEDB.12.0 (hereinafter referred to as ACE engine)
String oledbconnstring = @ "Provider=microsoft.ace.oledb.12.0;data source=e:\programme\ work \mypraticework\ test ODBC and Ole\ Test ODBC and OLE\BIN\DEBUG\DBXS.ACCDB ";
OleDbConnection connole = new OleDbConnection (oledbconnstring);
Connole.open ();
OleDbCommand commandole = Connole.createcommand ();
Commandole.commandtext = "SELECT * from UserInfo";
OleDbDataReader reader = Commandole.executereader (System.Data.CommandBehavior.CloseConnection);
while (reader. Read ())
{
Console.WriteLine ("Data: name {0}", reader.) GetString (1));
Console.WriteLine ("Data: name {0}, age {1}, gender {2}", reader.) GetString (1), reader. GetValue (2), reader. GetValue (3));
}
Console.read ();
}
}
}
Test ODBC with OLE