//create the database connection
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Sample.mdb");
String strSql = "select * from SampleTable";
OleDbCommand aCommand = new OleDbCommand(strSql, aConnection);
aConnection.Open();
//create the datareader object to connect to table
OleDbDataReader aReader = aCommand.ExecuteReader();
while(aReader.Read())
{
Console.WriteLine(aReader.GetString(0));
}
//close the reader
aReader.Close();
//close the connection is important.
aConnection.Close();
//create the database connection
OleDbConnection aConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Sample.mdb");
String strSql = "select * from SampleTable";
OleDbCommand aCommand = new OleDbCommand(strSql, aConnection);
aConnection.Open();
//create the datareader object to connect to table
OleDbDataReader aReader = aCommand.ExecuteReader();
while(aReader.Read())
{
Console.WriteLine(aReader.GetString(0));
}
//close the reader
aReader.Close();
//close the connection is important.
aConnection.Close();