// All namespaces used in the import program
Using system;
Using system. Data. oledb;
Using system. Windows. forms;
Class oledbtest {
Public static void main (){
// Establish a connection to the database
String strconnect = "provider = Microsoft. Jet. oledb.4.0; Data Source =" + application. startuppath + "\ My. mdb ";
Oledbconnection aconnection = new oledbconnection (strconnect );
// Design the content of the dataset to be returned
Oledbcommand acommand = new oledbcommand ("select * from persons", aconnection );
Try {
// Open the connection to the database
AConnection. Open ();
// Return the required dataset content
OleDbDataReader aReader = aCommand. ExecuteReader ();
Console. WriteLine ("The following is all the content of a field in the opened dataset! ");
// Display all content of the first field of the dataset. If you want the second field to change "0" to "1"
While (aReader. Read ()){
Console. WriteLine (aReader. GetString (0 ));
}
// Close the dataset
AReader. Close ();
// Close the connection to the database
Aconnection. Close ();
}
Catch (oledbexception E)
{
// If an error occurs, the error message is output.
Console. writeline ("Error Type:", E. errors [0]. Message );
}
}
}