Reading Access Data : Access « Database ADO.net « C# / C Sharp






Reading Access Data

 
using System;
using System.Data;           
using System.Data.OleDb;     
using System.Collections.Generic;
using System.Text;

class Program {
    static void Main(string[] args) {
        OleDbConnection thisConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\nwind.mdb");
        thisConnection.Open();
        OleDbCommand thisCommand = thisConnection.CreateCommand();
        thisCommand.CommandText = "SELECT CustomerID, CompanyName FROM Customers";
        OleDbDataReader thisReader = thisCommand.ExecuteReader();
        while (thisReader.Read()) {
            Console.WriteLine("\t{0}\t{1}",thisReader["CustomerID"], thisReader["CompanyName"]);
        }
        thisReader.Close();
        thisConnection.Close();
    }
}

 








Related examples in the same category

1.Connects to a Microsoft Access databaseConnects to a Microsoft Access database
2.How to use an OleDbConnection object to connect to an Access database
3.Use OdbcCommand to read data in Access database and fill the DataGrid
4.Read query result data from Access database
5.Connect to an Access database file