【C#学习笔记】读access2007

using System;
using System.Data.OleDb;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string strConnection = "Provider = Microsoft.ACE.OLEDB.12.0;";
            strConnection += @"Data Source = c:/Database1.accdb ";
            OleDbConnection con = new OleDbConnection(strConnection);
            con.Open();

            OleDbCommand com = con.CreateCommand();
            com.CommandText = "SELECT * FROM 表1";

            OleDbDataReader reader = com.ExecuteReader();

            while (reader.Read())
            {             
                Console.WriteLine((string)reader["姓名"]+"  "+(int)reader["年龄"]+"  "+(string)reader["性别"]);
            }
            reader.Close();
            con.Close();

            Console.Read();
        }      
    }
}

 

posted @ 2017-08-27 15:10  Dsp Tian  阅读(525)  评论(0编辑  收藏  举报