using System.Data;
using System.Data.Odbc;
// Username
string sUID = @"user";
// Passwort
string sPW = @"password";
// Access-Datei
string sMDB = @"C:\Temp\Northwind.mdb";
// SQL-String
string sSql = @"SELECT Names FROM MyTable";
OdbcConnection conn = null;
OdbcDataReader reader = null;
try
{
// Verbindung herstellen
conn = new OdbcConnection("Driver={Microsoft Access Driver (*.mdb)};DBQ=" + sMDB + ";UID=" + sUID + ";PWD=" + sPW + ";");
conn.Open();
// SQL-Kommando abschicken
OdbcCommand cmd = new OdbcCommand(sSql, conn);
reader = cmd.ExecuteReader();
// Daten auslesen und anzeigen
while (reader.Read())
{
Console.WriteLine(reader["Names"]);
}
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex);
}
finally
{
// aufräumen
if (reader != null) reader.Close();
if (conn != null) conn.Close();
}