stdafx.h中
#pragma once
#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#import"C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","rsEOF")
// TODO: reference additional headers your program requires here
主程序中(以下代码修改自孙鑫VC++深入详解)
代码
#include "stdafx.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int end;
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString="Provider=SQLOLEDB.1;Password=finally;Persist Security Info=True; User ID=sa;Initial Catalog=pubs";
pConn->Open("","","",adConnectUnspecified);
pRst=pConn->Execute("select * from authors",NULL,adCmdText);
while(!pRst->rsEOF)
{
cout<<((_bstr_t)pRst->GetCollect("au_lname"))<<endl;;
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
cin>>end;
return 0;
}
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int end;
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset));
pConn->ConnectionString="Provider=SQLOLEDB.1;Password=finally;Persist Security Info=True; User ID=sa;Initial Catalog=pubs";
pConn->Open("","","",adConnectUnspecified);
pRst=pConn->Execute("select * from authors",NULL,adCmdText);
while(!pRst->rsEOF)
{
cout<<((_bstr_t)pRst->GetCollect("au_lname"))<<endl;;
pRst->MoveNext();
}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();
cin>>end;
return 0;
}