1 using System; 2 using System.Data; 3 using System.Data.OleDb; 4 /** 5 * @author Donie 6 */ 7 namespace mono_csharp 8 { 9 class MainClass 10 { 11 public static void Main (string[] args) 12 { 13 //创建access数据库连接 14 string strConnection="provider=microsoft.jet.oledb.4.0;data source=./Database.mdb"; 15 //创建sql语句 16 string sql="select oldtext from md5"; 17 //new 一个数据库连接 18 OleDbConnection objConnection=new OleDbConnection(strConnection); 19 //得到command对象 20 OleDbCommand accessComm = new OleDbCommand(sql,objConnection); 21 //打开数据库连接 22 objConnection.Open(); 23 //执行sql语句得到 Reader对象 24 OleDbDataReader _reader = accessComm.ExecuteReader(); 25 //从reader中拿出数据 并打印出来 26 while(_reader.Read()) 27 { 28 Console.WriteLine(_reader.GetString(0).ToString()); 29 } 30 31 //关闭数据库连接 32 objConnection.Close(); 33 34 } 35 } 36 }