Read data from Access database : Access « ADO.Net « C# / CSharp Tutorial






using System;
using System.Data;
using System.Data.Common;
using System.Data.OleDb;

class MainClass
{
  static void Main(string[] args)
  {
    string connectionString = "Provider=Microsoft.JET.OLEDB.4.0;data source=C:\\Northwind.mdb";

    OleDbConnection conn = new OleDbConnection(connectionString);

    string sql = "SELECT * FROM Orders";
                                          
    OleDbCommand cmd = new OleDbCommand(sql, conn);

    conn.Open();

    OleDbDataReader reader;
    reader = cmd.ExecuteReader();

    while (reader.Read()) 
    {
      Console.Write(reader.GetString(0).ToString() + " ," );
      Console.Write(reader.GetString(1).ToString() + " ," );
      Console.WriteLine("");
    }

    reader.Close();
    conn.Close();
  }
}








32.1.Access
32.1.1.Connecting To Access
32.1.2.Use OleDbCommand to load data from Access database mdb
32.1.3.Read data from Access database
32.1.4.use an OleDbCommand object to read data from Access database
32.1.5.Connecting to a Microsoft Access Database
32.1.6.Connecting to a Password-Protected Microsoft Access Database