#using // Add aclearcase/" target="_blank" >ccess to .NET Framework classes. #using #using using namespace System; using namespace System::Data::ADO; |
int main(void) { ADOConnection* connection; // ADO connection. ADOCommand* command; // ADO command ADODataReader* dataReader; // ADO data reader try { // Create connection, set connection string and open connection to // specified database. connection = new ADOConnection(); connection->ConnectionString = S"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\Data\\grocertogo.mdb;Persist Security Info=False"; connection->Open(); // Create command and get data reader by executing this command. command = new ADOCommand(S"SELECT ProductName, UnitPrice FROM Products", connection); command->Execute(&dataReader); // Print table header Console::WriteLine(S"_____________________________________"); Console::WriteLine(S"Product | Price"); Console::WriteLine(S"_____________________________________"); // Iterate through rows set and print data. while(dataReader->Read()) Console::WriteLine(S"{0, -30}| {1}", dataReader->get_Item("ProductName"), dataReader->get_Item("UnitPrice")); // Print table footer. Console::WriteLine(S"_____________________________________"); // Close DataReader dataReader->Close(); // Close connection. connection->Close(); } catch(Exception* e) { // Print error message and close connection. Console::WriteLine("Error occured: {0}", e->Message); if (dataReader && !dataReader->IsClosed) dataReader->Close(); if (connection->State == DBObjectState::Open) connection->Close(); } Console::WriteLine("Press ENTER to continue"); Console::ReadLine(); return 0; } |