static void Main()
{
try
{
con = new OleDbConnection(@"Provider=Microsoft.JET.OLEDB.4.0;" + @"data source=contact.mdb;Jet OLEDB:Database Password=123456"); // connection string change database name and password here.
con.Open(); //connection must be openned
OleDbCommand cmd = new OleDbCommand("SELECT * from contact", con); // creating query command
OleDbDataReader reader = cmd.ExecuteReader(); // executes query
while(reader.Read()) // if can read row from database
{
Console.WriteLine(reader.GetValue(1).ToString() + " = " + reader.GetValue(3).ToString()); // Get column 1 and column 3 value and print
}
}
catch(Exception ex)
{
Console.WriteLine("Ex: "+ex); // shows exception message in console if any errors occured
}
finally
{
con.Close(); // finally closes connection
}
}