码迷,mamicode.com
首页 > 数据库 > 详细

测试ODBC与OLE

时间:2016-03-26 12:34:47      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

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();
}
}
}

测试ODBC与OLE

标签:

原文地址:http://www.cnblogs.com/1175429393wljblog/p/5322477.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!