using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
namespace AddressBook
{
class Program
{
static void Main(string[] args)
{
//Create the database connection
OleDbConnection oleConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=AddressBook.mdb");
//Create the command object and store the sql query
OleDbCommand oleCommand = new OleDbCommand("SELECT * FROM tbl_address_book", oleConnection);
try
{
//Open the connection
oleConnection.Open();
//Create the DataReader object to connect to table
OleDbDataReader oleDataReader = oleCommand.ExecuteReader();
//While loop used to get all the records in the table and display them in the
//Console window.
while (oleDataReader.Read())
{
Console.WriteLine(oleDataReader.GetString(0) + "\t" + oleDataReader.GetString(1) + "\t" + oleDataReader.GetString(2) + "\t" + oleDataReader.GetString(3));
}
//Close the connection
oleConnection.Close();
//Use the Read() method of the Console Class to keep the Console window open.
Console.Read();
}
//Catch an error is it occurs and display it in the Console window.
catch (OleDbException ex)
{
Console.WriteLine(ex.Message);
Console.Read();
}
}
}
}
Sunday, February 20, 2011
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment