s21_06.cpp

来自「本书分为五个部分」· C++ 代码 · 共 55 行

CPP
55
字号
// 这是使用应用程序向导生成的 VC++ 
// 应用程序项目的主项目文件。

#include "stdafx.h"

#using <mscorlib.dll>
#include <tchar.h>

// 显示引用命名空间
#using <System.dll>
#using <System.Data.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Data;
using namespace System::Data::SqlClient;
using namespace System::Data::OleDb;
using namespace System::Xml;

// 这是此应用程序的入口点
int _tmain(void)
{
    // 设置连接和查询字符串
    String* strConnection = 
        S"Provider=Microsoft.Jet.OLEDB.4.0;" \
        S"Data Source=D:\\visual studio projects\\database\\ENorthwind.mdb;";
    String* strSQL = S"SELECT * FROM Categories";

    // 创建Connection和DataAdapter对象
    OleDbConnection* nwindConn = 
        new OleDbConnection(strConnection);
    OleDbDataAdapter* custAD = 
        new OleDbDataAdapter(strSQL, nwindConn);

    // 自动生成命令
    OleDbCommandBuilder* custCD = 
        new OleDbCommandBuilder(custAD);
    custAD->UpdateCommand = custCD->GetUpdateCommand();
    custAD->InsertCommand = custCD->GetInsertCommand();
    custAD->DeleteCommand = custCD->GetDeleteCommand();

    // 显示自动生成命令的命令字符串
    Console::WriteLine(S"SelectCommand = \n{0}", 
        custAD->SelectCommand->CommandText);
    Console::WriteLine(S"UpdateCommand = \n{0}", 
        custAD->UpdateCommand->CommandText);
    Console::WriteLine(S"InsertCommand = \n{0}", 
        custAD->InsertCommand->CommandText);
    Console::WriteLine(S"DeleteCommand = \n{0}", 
        custAD->DeleteCommand->CommandText);

    nwindConn->Close();

    return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?