《VC++深入详解》中的使用ADO对象连接数据by VC++一例

来源:互联网 发布:开淘宝网店的费用 编辑:程序博客网 时间:2024/06/07 15:18
// consoleMfc.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include "consoleMfc.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename ("EOF", "rsEOF")/////////////////////////////////////////////////////////////////////////////// The one and only application objectCWinApp theApp;using namespace std;int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]){int nRetCode = 0;// initialize MFC and print and error on failureif (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)){// TODO: change error code to suit your needscerr << _T("Fatal Error: MFC initialization failed") << endl;nRetCode = 1;}else{// TODO: code your application's behavior here.CoInitialize(NULL);_ConnectionPtr pConn(__uuidof(Connection));_RecordsetPtr pRst(__uuidof(Recordset));_CommandPtr pCmd(__uuidof(Command));pConn->ConnectionString="Provider=MSDASQL.1;Password=123456;Persist Security Info=True;User ID=root;Data Source=xs_kc";pConn->Open("","","",adConnectUnspecified);pRst=pConn->Execute("select * from xs",NULL,adCmdText);while(!pRst->rsEOF){_bstr_t bst = (_bstr_t)pRst->GetCollect("姓名");// 其中的姓名可以使用打开的表中的字段名替换cout << (char*)(bst) << endl;pRst->MoveNext();}pRst->Close();pConn->Close();pCmd.Release();pRst.Release();pConn.Release();CoUninitialize();}return nRetCode;}

如果不加#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename ("EOF", "rsEOF"), 编译时会提示_ConnectionPtr、_RecordsetPtr、_CommandPtr undeclared   identifier
原创粉丝点击