标签:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Odbc;
using System.Data.OleDb;
namespace 测试ODBC与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("数据:姓名{0}", reader.GetString(1));
// Console.WriteLine("数据:姓名{0},年龄{1},性别{2}", read.GetString(1), read.GetValue(2), read.GetValue(3));
//}
//Console.Read();
//OleDb
//连接Access数据库
//Microsoft.Jet.OLEDB.4.0(以下简称 Jet 引擎)
//string oledbConnstring = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Programme\工作\MyPraticeWork\测试ODBC与OLE\测试ODBC与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("数据:姓名{0}", reader.GetString(0));
// //Console.WriteLine("数据:姓名{0},年龄{1},性别{2}", reader.GetString(0), reader.GetString(1), reader.GetString(2));
//}
//Console.Read();
//Microsoft.ACE.OLEDB.12.0(以下简称 ACE 引擎)
string oledbConnstring = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\Programme\工作\MyPraticeWork\测试ODBC与OLE\测试ODBC与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("数据:姓名{0}", reader.GetString(1));
Console.WriteLine("数据:姓名{0},年龄{1},性别{2}", reader.GetString(1), reader.GetValue(2), reader.GetValue(3));
}
Console.Read();
}
}
}
标签:
原文地址:http://www.cnblogs.com/1175429393wljblog/p/5322477.html