扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:Tacone译 来源:51dotnet 2007年11月16日
关键字: managed C++ 应用 ADO
#using // Add access 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; } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者